Tutorial by Examples: al

A long-form syntax is available for defining multi-line functions. This can be useful when we use imperative structures such as loops. The expression in tail position is returned. For instance, the below function uses a for loop to compute the factorial of some integer n: function myfactorial(n) ...
Deferred function calls serve a similar purpose to things like finally blocks in languages like Java: they ensure that some function will be executed when the outer function returns, regardless of if an error occurred or which return statement was hit in cases with multiple returns. This is useful f...
Sometimes a RecyclerView will need to use several types of Views to be displayed in the list shown in the UI, and each View needs a different layout xml to be inflated. For this issue, you may use different ViewHolders in single Adapter, by using a special method in RecyclerView - getItemViewType(i...
If logic of generic class or method requires checking equality of values having generic type, use EqualityComparer<TType>.Default property: public void Foo<TBar>(TBar arg1, TBar arg2) { var comparer = EqualityComparer<TBar>.Default; if (comparer.Equals(arg1,arg2) {...
To simulate a phone call, press the 'Extended controls' button indicated by three dots, choose 'Phone' and select 'Call'. You can also optionally change the phone number.
We can omit the argument in the call if that argument is an Optional Argument Every Optional Argument has its own default value It will take default value if we do not supply the value A default value of a Optional Argument must be a Constant expression. Must be a value type such as enum or s...
The ref keyword for callers of methods is now optional when calling into methods supplied by COM interfaces. Given a COM method with the signature void Increment(ref int x); the invocation can now be written as either Increment(0); // no need for "ref" or a place holder variable any m...
The IQueryable and IQueryable<T> interfaces allows developers to translate a LINQ query (a 'language-integrated' query) to a specific datasource, for example a relational database. Take this LINQ query written in C#: var query = from book in books where book.Author == "Steph...
XML <College> <FootBall> <Members>20</Members> <Coach>Archie Theron</Coach> <Name>Wild cats</Name> <StarPlayer>David Perry</StarPlayer> </FootBall> <VolleyBall> <Me...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[@name='Sun'] or //*[@name='Sun'] OUTPUT <C...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[contains(@name,'Ear')] or //*[contains(@name,'Ear...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[contains(lower-case(@name),'ear')] or //*[contain...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[starts-with(lower-case(@name),'ear')] or //*[star...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[ends-with(lower-case(@type),'tar')] or //*[ends-w...
This example uses Parallel.ForEach to calculate the sum of the numbers between 1 and 10000 by using multiple threads. To achieve thread-safety, Interlocked.Add is used to sum the numbers. using System.Threading; int Foo() { int total = 0; var numbers = Enumerable.Range(1, 10000).ToLis...
This example uses Parallel.For to calculate the sum of the numbers between 1 and 10000 by using multiple threads. To achieve thread-safety, Interlocked.Add is used to sum the numbers. using System.Threading; int Foo() { int total = 0; Parallel.For(1, 10001, () => 0, // in...
While System.Diagnostics.Contracts is included within the .Net Framework. To use Code Contracts you must install the Visual Studio extensions. Under Extensions and Updates search for Code Contracts then install the Code Contracts Tools After the tools are installed you must enable Code Contract...
Conditional contexts in Lua (if, elseif, while, until) do not require a boolean. Like many languages, any Lua value can appear in a condition. The rules for evaluation are simple: false and nil count as false. Everything else counts as true. if 1 then print("Numbers work.") ...
K&R void* is a catch all type for pointers to object types. An example of this in use is with the malloc function, which is declared as void* malloc(size_t); The pointer-to-void return type means that it is possible to assign the return value from malloc to a pointer to any other type of ob...
Conditional expressions can be done with ~[ and ~]. The clauses of the expression are separated using ~;. By default, ~[ takes an integer from the argument list, and picks the corresponding clause. The clauses start at zero. (format t "~@{~[First clause~;Second clause~;Third clause~;Fourth cl...

Page 81 of 269