Tutorial by Examples

Anonymous types allow the creation of objects without having to explicitly define their types ahead of time, while maintaining static type checking. var anon = new { Value = 1 }; Console.WriteLine(anon.Id); // compile time error Conversely, dynamic has dynamic type checking, opting for runtime ...
Generic methods allow the use of anonymous types through type inference. void Log<T>(T obj) { // ... } Log(new { Value = 10 }); This means LINQ expressions can be used with anonymous types: var products = new[] { new { Amount = 10, Id = 0 }, new { Amount = 20, Id = 1 }, ...
Using generic constructors would require the anonymous types to be named, which is not possible. Alternatively, generic methods may be used to allow type inference to occur. var anon = new { Foo = 1, Bar = 2 }; var anon2 = new { Foo = 5, Bar = 10 }; List<T> CreateList<T>(params T[] it...
Anonymous type equality is given by the Equals instance method. Two objects are equal if they have the same type and equal values (through a.Prop.Equals(b.Prop)) for every property. var anon = new { Foo = 1, Bar = 2 }; var anon2 = new { Foo = 1, Bar = 2 }; var anon3 = new { Foo = 5, Bar = 10 }; ...
Arrays of anonymous types may be created with implicit typing. var arr = new[] { new { Id = 0 }, new { Id = 1 } };
To remove a cookie, set the expiry timestamp to a time in the past. This triggers the browser's removal mechanism: setcookie('user', '', time() - 3600, '/'); When deleting a cookie make sure the path and domain parameters of setcookie() matches the cookie you're trying to delete or a new cooki...
A view can filter some rows from the base table or project only some columns from it: CREATE VIEW new_employees_details AS SELECT E.id, Fname, Salary, Hire_date FROM Employees E WHERE hire_date > date '2015-01-01'; If you select form the view: select * from new_employees_details IdFNam...
A view can be a really complex query(aggregations, joins, subqueries, etc). Just be sure you add column names for everything you select: Create VIEW dept_income AS SELECT d.Name as DepartmentName, sum(e.salary) as TotalSalary FROM Employees e JOIN Departments d on e.DepartmentId = d.id GROUP BY...
C11 C11 introduced support for multiple threads of execution, which affords the possibility of data races. A program contains a data race if an object in it is accessed1 by two different threads, where at least one of the accesses is non-atomic, at least one modifies the object, and program seman...
round Rounds the value to the nearest whole number with x.5 rounding up (but note that -x.5 rounds down). round(3.000) // 3 round(3.001) // 3 round(3.499) // 3 round(3.500) // 4 round(3.999) // 4 round(-3.000) // -3 round(-3.001) // -3 round(-3.499) // -3 round(-3.500) // -4 *** careful...
arc4random_uniform(someNumber: UInt32) -> UInt32 This gives you random integers in the range 0 to someNumber - 1. The maximum value for UInt32 is 4,294,967,295 (that is, 2^32 - 1). Examples: Coin flip let flip = arc4random_uniform(2) // 0 or 1 Dice roll let roll = arc4random_...
What is Serialization Serialization is the process of converting an object's state (including its references) to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time. Serialization is used when you want to persist the object. It is also used b...
If you have cloned a fork (e.g. an open source project on Github) you may not have push access to the upstream repository, so you need both your fork but be able to fetch the upstream repository. First check the remote names: $ git remote -v origin https://github.com/myusername/repo.git (fetch...
Installing Visual Studio If you do not have Visual Studio installed, you can download the free Visual Studio Community Edition here. If you already have it installed, you can proceed to the next step. Creating an ASP.NET Core MVC Application. Open Visual Studio. Select File > New Project. ...
By default, all the methods declared in a protocol are required. This means that any class that conforms to this protocol must implement those methods. It is also possible to declare optional methods. These method can be implemented only if needed. You mark optional methods with the @optional dire...
The following syntax indicate that a class adopts a protocol, using angle brackets. @interface NewClass : NSObject <NewProtocol> ... @end This means that any instance of NewClass will respond to methods declared in its interface but also it will provide an implementation for all the requ...
If you screw up a rebase, one option to start again is to go back to the commit (pre rebase). You can do this using reflog (which has the history of everything you've done for the last 90 days - this can be configured): $ git reflog 4a5cbb3 HEAD@{0}: rebase finished: returning to refs/heads/foo 4...
The typeof operator works on type parameters. class NameGetter<T> { public string GetTypeName() { return typeof(T).Name; } }
toList flattens a Foldable structure t a into a list of as. ghci> toList [7, 2, 9] -- t ~ [] [7, 2, 9] ghci> toList (Right 'a') -- t ~ Either e "a" ghci> toList (Left "foo") -- t ~ Either String [] ghci> toList (3, True) -- t ~ (,) Int [True] toList is ...
When json_encode or json_decode fails to parse the string provided, it will return false. PHP itself will not raise any errors or warnings when this happens, the onus is on the user to use the json_last_error() and json_last_error_msg() functions to check if an error occurred and act accordingly in ...

Page 99 of 1336