Tutorial by Examples: c

The using keyword ensures that the resource defined within the statement only exists within the scope of the statement itself. Any resources defined within the statement must implement the IDisposable interface. These are incredibly important when dealing with any connections that implement the IDi...
To do this you need a reference to the assembly which contains the type. If you have another type available which you know is in the same assembly as the one you want you can do this: typeof(KnownType).Assembly.GetType(typeName); where typeName is the name of the type you are looking for (incl...
Problem: You need to match text of a certain format, for example: 1-a-0 6/p/0 4 g 0 That's a digit, a separator (one of -, /, or a space), a letter, the same separator, and a zero. Naïve solution: Adapting the regex from the Basics example, you come up with this regex: [0-9]([-/ ])[a-z]\...
In addition to break, there is also the keyword continue. Instead of breaking completely the loop, it will simply skip the current iteration. It could be useful if you don't want some code to be executed if a particular value is set. Here's a simple example: for (int i = 1; i <= 10; i++) { ...
Extension methods can be used to "hide" processing of inelegant business rules that would otherwise require cluttering up a calling function with if/then statements. This is similar to and analogous to handling nulls with extension methods. For example, public static class CakeExtensions ...
If you need to write a file using different locale settings to the default, you can use std::locale and std::basic_ios::imbue() to do that for a specific file stream: Guidance for use: You should always apply a local to a stream before opening the file. Once the stream has been imbued you shoul...
Linux running systemd, like Ubuntu 16.04, adding -H tcp://0.0.0.0:2375 to /etc/default/docker does not have the effect it used to. Instead, create a file called /etc/systemd/system/docker-tcp.socket to make docker available on a TCP socket on port 4243: [Unit] Description=Docker Socket for the AP...
By default, a new class module is a Private class, so it is only available for instantiation and use within the VBProject in which it is defined. You can declare, instantiate and use the class anywhere in the same project: 'Class List has Instancing set to Private 'In any other module in the SAME ...
Group by is often used with join statement. Let's assume we have two tables. The first one is the table of students: IdFull NameAge1Matt Jones202Frank Blue213Anthony Angel18 Second table is the table of subject each student can take: Subject_IdSubject1Maths2P.E.3Physics And because one student c...
WITH SourceTableCTE AS ( SELECT * FROM SourceTable ) MERGE TargetTable AS target USING SourceTableCTE AS source ON (target.PKID = source.PKID) WHEN MATCHED THEN UPDATE SET target.ColumnA = source.ColumnA WHEN NOT MATCHED THEN INSERT (ColumnA) VALUES (Source.ColumnA);...
MERGE INTO TargetTable AS Target USING (VALUES (1,'Value1'), (2, 'Value2'), (3,'Value3')) AS Source (PKID, ColumnA) ON Target.PKID = Source.PKID WHEN MATCHED THEN UPDATE SET target.ColumnA= source.ColumnA WHEN NOT MATCHED THEN INSERT (PKID, ColumnA) VALUES (Source.PKID...
SELECT COALESCE(NULL, NULL, 'TechOnTheNet.com', NULL, 'CheckYourMath.com'); Result: 'TechOnTheNet.com' SELECT COALESCE(NULL, 'TechOnTheNet.com', 'CheckYourMath.com'); Result: 'TechOnTheNet.com' SELECT COALESCE(NULL, NULL, 1, 2, 3, NULL, 4); Result: 1
An object can only be deallocated by delete if it was allocated by new and is not an array. If the argument to delete was not returned by new or is an array, the behavior is undefined. An object can only be deallocated by delete[] if it was allocated by new and is an array. If the argument to delet...
USE msdb Go SELECT dbo.sysjobs.Name AS 'Job Name', 'Job Enabled' = CASE dbo.sysjobs.Enabled WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END, 'Frequency' = CASE dbo.sysschedules.freq_type WHEN 1 THEN 'Once' WHEN 4 THEN 'Daily' ...
WITHOUT_ARRAY_WRAPPER option in FOR JSON clause will remove array brackets from the JSON output. This is useful if you are returning single row in the query. Note: this option will produce invalid JSON output if more than one row is returned. Input table data (People table) IdNameAge1John232J...
OPENJSON function parses JSON text and returns multiple outputs. Values that should be returned are specified using the paths defined in the WITH clause. If a path is not specified for some column, the column name is used as a path. This function casts returned values to the SQL types defined in the...
Structures and arrays of structures can be initialized by a series of values enclosed in braces, one value per member of the structure. struct Date { int year; int month; int day; }; struct Date us_independence_day = { 1776, 7, 4 }; struct Date uk_battles[] = { { 1066, ...
A basic function is defined and executed like this: function hello($name) { print "Hello $name"; } hello("Alice");
Function arguments can be passed "By Reference", allowing the function to modify the variable used outside the function: function pluralize(&$word) { if (substr($word, -1) == 'y') { $word = substr($word, 0, -1) . 'ies'; } else { $word .= 's'; } } $w...
An object in PHP contains variables and functions. Objects typically belong to a class, which defines the variables and functions that all objects of this class will contain. The syntax to define a class is: class Shape { public $sides = 0; public function description() { ...

Page 383 of 826