Tutorial by Examples: c

The simplest example of an injection in an Angular app - injecting $scope to an Angular Controller: angular.module('myModule', []) .controller('myController', ['$scope', function($scope) { $scope.members = ['Alice', 'Bob']; ... }]) The above illustrates an injection of a $scope into ...
There is also an option to dynamically request components. You can do it using the $injector service: myModule.controller('myController', ['$injector', function($injector) { var myService = $injector.get('myService'); }]); Note: while this method could be used to prevent the circular depen...
Equivalently, we can use the $inject property annotation to achieve the same as above: var MyController = function($scope) { // ... } MyController.$inject = ['$scope']; myModule.controller('MyController', MyController);
The Switch statement works very well with Enum values enum CarModel { case Standard, Fast, VeryFast } let car = CarModel.Standard switch car { case .Standard: print("Standard") case .Fast: print("Fast") case .VeryFast: print("VeryFast") } Since we ...
From MSDN: An enumeration type (also named an enumeration or an enum) provides an efficient way to define a set of named integral constants that may be assigned to a variable. Essentially, an enum is a type that only allows a set of finite options, and each option corresponds to a number. By d...
To duplicate a table, simply do the following: CREATE TABLE newtable LIKE oldtable; INSERT newtable SELECT * FROM oldtable;
Match any: Must match at least one string. In this example the product type must be either 'electronics', 'books', or 'video'. SELECT * FROM purchase_table WHERE product_type LIKE ANY ('electronics', 'books', 'video'); Match all (must meet all requirements). In this example both 'united...
CREATE SEQUENCE orders_seq START WITH 1000 INCREMENT BY 1; Creates a sequence with a starting value of 1000 which is incremented by 1.
a reference to seq_name.NEXTVAL is used to get the next value in a sequence. A single statement can only generate a single sequence value. If there are multiple references to NEXTVAL in a statement, they use will use the same generated number. NEXTVAL can be used for INSERTS INSERT INTO Orders (Or...
string dateFormat = "MM/dd/yyyy hh:mm:ss.fffffff"; DateTime date1 = new DateTime(2010, 9, 8, 16, 0, 0); Console.WriteLine("Original date: {0} ({1:N0} ticks)\n", date1.ToString(dateFormat), date1.Ticks); DateTime date2 = date1.AddMilliseconds(1); Console....
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0); DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0); int result = DateTime.Compare(date1, date2); string relationship; if (result < 0) relationship = "is earlier than"; else if (result == 0) relationship = "is the...
Once the instance of the BackgroundWorker has been declared, it must be given properties and event handlers for the tasks it performs. /* This is the backgroundworker's "DoWork" event handler. This method is what will contain all the work you wish to have your progra...
This allows the BackgroundWorker to be cancelled in between tasks bgWorker.WorkerSupportsCancellation = true; This allows the worker to report progress between completion of tasks... bgWorker.WorkerReportsProgress = true; //this must also be used in conjunction with the ProgressChanged event...
A BackgroundWorker is commonly used to perform tasks, sometimes time consuming, without blocking the UI thread. // BackgroundWorker is part of the ComponentModel namespace. using System.ComponentModel; namespace BGWorkerExample { public partial class ExampleForm : Form { ...
The following example demonstrates the use of a BackgroundWorker to update a WinForms ProgressBar. The backgroundWorker will update the value of the progress bar without blocking the UI thread, thus showing a reactive UI while work is done in the background. namespace BgWorkerExample { public...
Python supports a translate method on the str type which allows you to specify the translation table (used for replacements) as well as any characters which should be deleted in the process. str.translate(table[, deletechars]) ParameterDescriptiontableIt is a lookup table that defines the mappin...
The foreach package brings the power of parallel processing to R. But before you want to use multi core CPUs you have to assign a multi core cluster. The doSNOW package is one possibility. A simple use of the foreach loop is to calculate the sum of the square root and the square of all numbers from...
Properties can be added with categories using associated objects, a feature of the Objective-C runtime. Note that the property declaration of retain, nonatomic matches the last argument to objc_setAssociatedObject. See Attach object to another existing object for explanations. #import <objc/run...
Extension methods are useful to extend the behaviour of libraries we don't own. They are used similar to instance methods thanks to the compiler's syntactic sugar: Sub Main() Dim stringBuilder = new StringBuilder() 'Extension called directly on the object. stringBuilder.AppendIf(t...
A good use of extension method is to make the language more functional Sub Main() Dim strings = { "One", "Two", "Three" } strings.Join(Environment.NewLine).Print() End Sub <Extension> Public Function Join(strings As IEnumerable(Of String), separa...

Page 120 of 826