Tutorial by Examples

The ToDictionary() LINQ method can be used to generate a Dictionary<TKey, TElement> collection based on a given IEnumerable<T> source. IEnumerable<User> users = GetUsers(); Dictionary<int, User> usersById = users.ToDictionary(x => x.Id); In this example, the single ar...
Grand Central Dispatch works on the concept of "Dispatch Queues". A dispatch queue executes tasks you designate in the order which they are passed. There are three types of dispatch queues: Serial Dispatch Queues (aka private dispatch queues) execute one task at a time, in order. They a...
3.0 To run tasks on a dispatch queue, use the sync, async, and after methods. To dispatch a task to a queue asynchronously: let queue = DispatchQueue(label: "myQueueName") queue.async { //do something DispatchQueue.main.async { //this will be called in main t...

int

int is an alias for System.Int32, which is a data type for signed 32-bit integers. This data type can be found in mscorlib.dll which is implicitly referenced by every C# project when you create them. Range: -2,147,483,648 to 2,147,483,647 int int1 = -10007; var int2 = 2132012521;
The long keyword is used to represent signed 64-bit integers. It is an alias for the System.Int64 datatype present in mscorlib.dll, which is implicitly referenced by every C# project when you create them. Any long variable can be declared both explicitly and implicitly: long long1 = 92233720368547...
Keyword used for unsigned 64-bit integers. It represents System.UInt64 data type found in mscorlib.dll which is implicitly referenced by every C# project when you create them. Range: 0 to 18,446,744,073,709,551,615 ulong veryLargeInt = 18446744073609451315; var anotherVeryLargeInt = 1544674406360...
Display multiple plots in one image with the different facet functions. An advantage of this method is that all axes share the same scale across charts, making it easy to compare them at a glance. We'll use the mpg dataset included in ggplot2. Wrap charts line by line (attempts to create a square l...
ggplot2 works best with a long data frame. The following sample data which represents the prices for sweets on 20 different days, in a format described as wide, because each category has a column. set.seed(47) sweetsWide <- data.frame(date = 1:20, chocolate = run...
Arrays are objects, but their type is defined by the type of the contained objects. Therefore, one cannot just cast A[] to T[], but each A member of the specific A[] must be cast to a T object. Generic example: public static <T, A> T[] castArray(T[] target, A[] array) { for (int i = 0; i...
Letters 3.0 let letters = CharacterSet.letters let phrase = "Test case" let range = phrase.rangeOfCharacter(from: letters) // range will be nil if no letters is found if let test = range { print("letters found") } else { print("letters not found") }...
A common question is how to juxtapose (combine) physically separate geographical regions on the same map, such as in the case of a choropleth describing all 50 American states (The mainland with Alaska and Hawaii juxtaposed). Creating an attractive 50 state map is simple when leveraging Google Maps...
Java doesn't provide a direct method in java.util.Arrays to remove an element from an array. To perform it, you can either copy the original array to a new one without the element to remove or convert your array to another structure allowing the removal. Using ArrayList You can convert the array t...
The + symbol marks a type parameter as covariant - here we say that "Producer is covariant on A": trait Producer[+A] { def produce: A } A covariant type parameter can be thought of as an "output" type. Marking A as covariant asserts that Producer[X] <: Producer[Y] prov...
By default all type parameters are invariant - given trait A[B], we say that "A is invariant on B". This means that given two parametrizations A[Cat] and A[Animal], we assert no sub/superclass relationship between these two types - it does not hold that A[Cat] <: A[Animal] nor that A[Ca...
The - symbol marks a type parameter as contravariant - here we say that "Handler is contravariant on A": trait Handler[-A] { def handle(a: A): Unit } A contravariant type parameter can be thought of as an "input" type. Marking A as contravariant asserts that Handler[X] &l...
Because collections are typically covariant in their element type*, a collection of a subtype may be passed where a super type is expected: trait Animal { def name: String } case class Dog(name: String) extends Animal object Animal { def printAnimalNames(animals: Seq[Animal]) = { anima...
Java provides specialized Streams for three types of primitives IntStream (for ints), LongStream (for longs) and DoubleStream (for doubles). Besides being optimized implementations for their respective primitives, they also provide several specific terminal methods, typically for mathematical operat...
The static keyword means 2 things: This value does not change from object to object but rather changes on a class as a whole Static properties and methods don't require an instance. public class Foo { public Foo{ Counter++; NonStaticCounter++; } public st...
The "static" keyword when referring to a class has three effects: You cannot create an instance of a static class (this even removes the default constructor) All properties and methods in the class must be static as well. A static class is a sealed class, meaning it cannot be inherite...
The following is a timer that fires at a fixed interval. It's timeout is defined by Period and it invokes a callback defined by Timerfcn upon timeout. t = timer; t.TasksToExecute = Inf; t.Period = 0.01; % timeout value in seconds t.TimerFcn = @(myTimerObj, thisEvent)disp('hello'); % timer callba...

Page 201 of 1336