Tutorial by Examples: er

int[] arr = new int[] {1, 6, 3, 3, 9}; for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); } using foreach: foreach (int element in arr) { Console.WriteLine(element); } using unsafe access with pointers https://msdn.microsoft.com/en-ca/library/y31yhkeb.asp...
Since PHP objects don't inherit from any base class (including stdClass), there is no support for type hinting a generic object type. For example, the below will not work. <?php function doSomething(object $obj) { return $obj; } class ClassOne {} class ClassTwo {} $classOne= new...
Type hinting for classes and interfaces was added in PHP 5. Class type hint <?php class Student { public $name = 'Chris'; } class School { public $name = 'University of Edinburgh'; } function enroll(Student $student, School $school) { echo $student->name . ' is b...
const fs = require('fs'); const readline = require('readline'); const rl = readline.createInterface({ input: fs.createReadStream('text.txt') }); // Each new line emits an event - every time the stream receives \r, \n, or \r\n rl.on('line', (line) => { console.log(line); }); ...
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('What is your name?', (name) => { console.log(`Hello ${name}!`); rl.close(); });
This example creates a trigger that inserts a record to a second table (MyAudit) after a record is inserted into the table the trigger is defined on (MyTable). Here the "inserted" table is a special table used by Microsoft SQL Server to store affected rows during INSERT and UPDATE statemen...
Adding the DebuggerDisplay Attribute will change the way the debugger displays the class when it is hovered over. Expressions that are wrapped in {} will be evaluated by the debugger. This can be a simple property like in the following sample or more complex logic. [DebuggerDisplay("{StringPr...
In Objective-C, method swizzling is the process of changing the implementation of an existing selector. This is possible due to the way Selectors are mapped on a dispatch table, or a table of pointers to functions or methods. Pure Swift methods are not dynamically dispatched by the Objective-C run...
In this approach, the single is accessed via the static method: Singleton.getInstance(); To enforce only one instance of the singleton, a private static variable retains the instance, while any additional attempts to instantiate an instance are enforced within the constructor. package { publ...
You can use git merge --squash to squash changes introduced by a branch into a single commit. No actual commit will be created. git merge --squash <branch> git commit This is more or less equivalent to using git reset, but is more convenient when changes being incorporated have a symbolic...
Math.random(); produces an evenly distributed random number between 0 (inclusive) and 1 (exclusive) Example output: 0.22282187035307288 0.3948539895936847 0.9987191134132445
function randomMinMax(min:Number, max:Number):Number { return (min + (Math.random() * Math.abs(max - min))); } This function is called by passing a range of minimum and maximum values. Example: randomMinMax(1, 10); Example outputs: 1.661770915146917 2.5521070677787066 9.4362709657...
Multiple rows can be inserted with a single insert command: INSERT INTO tbl_name (field1, field2, field3) VALUES (1,2,3), (4,5,6), (7,8,9); For inserting large quantities of data (bulk insert) at the same time, DBMS-specific features and recommendations exist. MySQL - LOAD DATA INFILE MSSQL - B...
int a = 1; int *a_pointer = &a; To dereference a_pointer and change the value of a, we use the following operation *a_pointer = 2; This can be verified using the following print statements. printf("%d\n", a); /* Prints 2 */ printf("%d\n", *a_pointer); /* Also prints...
public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Log("OnActionExecuting", filterContext.RouteData); } public override void OnActionExecuted(ActionExecute...
If you want to pass in values to a method when it is called, you use parameters: - (int)addInt:(int)intOne toInt:(int)intTwo { return intOne + intTwo; } The colon (:) separates the parameter from the method name. The parameter type goes in the parentheses (int). The parameter name goes aft...
@implemenetation Triangle ... -(void)setAngles:(NSArray *)_angles { self.angles = _angles; NSAssert((self.angles.count == 3), @"Triangles must have 3 angles. Array '%@' has %i", self.angles, (int)self.angles.count); CGFloat angleA = [self.angles[0] floatVal...
A Broadcast receiver is an Android component which allows you to register for system or application events. A receiver can be registered via the AndroidManifest.xml file or dynamically via the Context.registerReceiver() method. public class MyReceiver extends BroadcastReceiver { @Override ...
The where method is available on any ActiveRecord model and allows querying the database for a set of records matching the given criteria. The where method accepts a hash where the keys correspond to the column names on the table that the model represents. As a simple example, we will use the foll...
The where method on any ActiveRecord model can be used to generate SQL of the form WHERE column_name IN (a, b, c, ...). This is achieved by passing an array as argument. As a simple example, we will use the following model: class Person < ActiveRecord::Base #attribute :first_name, :string ...

Page 57 of 417