Tutorial by Examples: c

A class is also allowed to have static members, which can be either variables or functions. These are considered to be in the class' scope, but aren't treated as normal members; they have static storage duration (they exist from the start of the program to the end), aren't tied to a particular inst...
Join parent objects with their child entities, for example we want a relational table of each person and their hobbies DECLARE @json nvarchar(1000) = N'[ { "id":1, "user":{"name":"John"}, "hobbies":[ {...
When you also want to expose metadata without a config file you can build on the example programmatically creating a ServiceHost: public ConsoleHost() { mHost = new ServiceHost(typeof(Example), new Uri("http://localhost:8000/Example"), new Uri("net.tcp://9000/Example")); ...
Scope guards allow executing statements at certain conditions if the current block is left. import core.stdc.stdlib; void main() { int* p = cast(int*)malloc(int.sizeof); scope(exit) free(p); }
import std.stdio; void main() { writeln("<html>"); scope(exit) writeln("</html>"); { writeln("\t<head>"); scope(exit) writeln("\t</head>"); "\t\t<title>%s</title>".write...
Here we have a simple class to be tested that returns a Promise based on the results of an external ResponseProcessor that takes time to execute. For simplicty we'll assume that the processResponse method won't ever fail. import {processResponse} from '../utils/response_processor'; const ping =...
Selective imports can help to cleanup the namespace and speed-up the compile-time even more, because the compiler only needs to parse the specific, selected functions. import std.stdio: writeln; void main() { writeln("Hello world"); }
You can also import symbols in any scope, the import will only be looked up when the scope is needed (i.e. compiled) and the imported names will only be exposed in the imported scope. Most commonly the scope for local imports are functions, structs and classes. void main() { import std.stdio:...
Modules can be exposed to other modules with public imports. public import std.math; // only exports the symbol 'pow' public import std.math : pow;
Selective imports may also be renamed. void main() { import std.stdio : fooln = writeln; fooln("Hello world"); }
Modules have a one-to-one correspondence with source files. The module name is, by default, the file name with the path and extension stripped off, and can be set explicitly with the module declaration. The ModuleDeclaration sets the name of the module and what package it belongs to. If absent, the...
You can move a container instead of copying it: void print(const std::vector<int>& vec) { for (auto&& val : vec) { std::cout << val << ", "; } std::cout << std::endl; } int main() { // initialize vec1 with 1, 2, 3, 4 and...
You can re-use a moved object: void consumingFunction(std::vector<int> vec) { // Some operations } int main() { // initialize vec with 1, 2, 3, 4 std::vector<int> vec{1, 2, 3, 4}; // Send the vector by move consumingFunction(std::move(vec)); // Here...
Using using System.Text.RegularExpressions; Code static void Main(string[] args) { string input = "Carrot Banana Apple Cherry Clementine Grape"; // Find words that start with uppercase 'C' string pattern = @"\bC\w*\b"; MatchCollection matches = Regex.M...
A simple cursor syntax, operating on a few example test rows: /* Prepare test data */ DECLARE @test_table TABLE ( Id INT, Val VARCHAR(100) ); INSERT INTO @test_table(Id, Val) VALUES (1, 'Foo'), (2, 'Bar'), (3, 'Baz'); /* Test data prepared */ /* Iterator variabl...
COPY is PostgreSQL's bulk-insert mechanism. It's a convenient way to transfer data between files and tables, but it's also far faster than INSERT when adding more than a few thousand rows at a time. Let's begin by creating sample data file. cat > samplet_data.csv 1,Yogesh 2,Raunak 3,Varun ...
What is a Stack? In Java, Stacks are a LIFO (Last In, First Out) Data structure for objects. Stack API Java contains a Stack API with the following methods Stack() //Creates an empty Stack isEmpty() //Is the Stack Empty? Return Type: Boolean push(Item item) /...
Media queries allow one to apply CSS rules based on the type of device / media (e.g. screen, print or handheld) called media type, additional aspects of the device are described with media features such as the availability of color or viewport dimensions. General Structure of a Media Query @media ...
Proper indentation gives not only the aesthetic look but also increases the readability of the code. For example, consider the following code: %no need to understand the code, just give it a look n = 2; bf = false; while n>1 for ii = 1:n for jj = 1:n if ii+jj>30 bf = true; break end...
Assertions are used not to perform testing of input parameters, but to verify that program flow is corect -- i.e., that you can make certain assumptions about your code at a certain point in time. In other words: a test done with Debug.Assert should always assume that the value tested is true. Debu...

Page 364 of 826