Tutorial by Examples: el

using System; class Program { // The Main() function is the first function to be executed in a program static void Main() { // Write the string "Hello World to the standard out Console.WriteLine("Hello World"); } } Console.WriteLine has se...
Equals Checks whether the supplied operands (arguments) are equal "a" == "b" // Returns false. "a" == "a" // Returns true. 1 == 0 // Returns false. 1 == 1 // Returns true. false == true // Returns false. false == false // Return...
<Foo> <Dog/> </Foo> public class Foo { // Using XmlElement [XmlElement(Name="Dog")] public Animal Cat { get; set; } }
var persons = new[] { new {Id = 1, Name = "Foo"}, new {Id = 2, Name = "Bar"}, new {Id = 3, Name = "Fizz"}, new {Id = 4, Name = "Buzz"} }; var names = persons.Select(p => p.Name); Console.WriteLine(string.Join(",", names....
Enumerable.Select returns an output element for every input element. Whereas Enumerable.SelectMany produces a variable number of output elements for each input element. This means that the output sequence may contain more or fewer elements than were in the input sequence. Lambda expressions passe...
var names = new[] {"Foo","Bar","Fizz","Buzz"}; var thirdName = names.ElementAt(2); Console.WriteLine(thirdName); //Fizz //The following throws ArgumentOutOfRangeException var minusOnethName = names.ElementAt(-1); var fifthName = names.ElementAt(4); ...
var names = new[] {"Foo","Bar","Fizz","Buzz"}; var thirdName = names.ElementAtOrDefault(2); Console.WriteLine(thirdName); //Fizz var minusOnethName = names.ElementAtOrDefault(-1); Console.WriteLine(minusOnethName); //null var fifthName = names.Eleme...
public delegate int ModifyInt(int input); ModifyInt multiplyByTwo = x => x * 2; The above Lambda expression syntax is equivalent to the following verbose code: public delegate int ModifyInt(int input); ModifyInt multiplyByTwo = delegate(int x){ return x * 2; };
var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; var task = new Task((state) => { int i = 1; var myCancellationToken = (CancellationToken)state; while(true) { Console.Write...
var actions = Enumerable.Range(1, 10).Select(n => new Action(() => { Console.WriteLine("I'm task " + n); if((n & 1) == 0) throw new Exception("Exception from task " + n); })).ToArray(); try { Parallel.Invoke(actions); } catch(AggregateExc...
Imports System Module Program Public Sub Main() Console.WriteLine("Hello World") End Sub End Module Live Demo in Action at .NET Fiddle Introduction to Visual Basic .NET
open System [<EntryPoint>] let main argv = printfn "Hello World" 0 Live Demo in Action at .NET Fiddle Introduction to F#
Select allows you to apply a transformation to every element in any data structure implementing IEnumerable. Getting the first character of each string in the following list: List<String> trees = new List<String>{ "Oak", "Birch", "Beech", "Elm", ...
emails.Subscribe(email => Console.WriteLine("Email from {0} to {1}", email.From, email.To), cancellationToken);
var sequenceOfSequences = new [] { new [] { 1, 2, 3 }, new [] { 4, 5 }, new [] { 6 } }; var sequence = sequenceOfSequences.SelectMany(x => x); // returns { 1, 2, 3, 4, 5, 6 } Use SelectMany() if you have, or you are creating a sequence of sequences, but you want the result as one long sequen...
The SelectMany linq method 'flattens' an IEnumerable<IEnumerable<T>> into an IEnumerable<T>. All of the T elements within the IEnumerable instances contained in the source IEnumerable will be combined into a single IEnumerable. var words = new [] { "a,b,c", "d,e&quo...
public string Foobar { get { return _foobar; } set { _foobar = value; } } private string _foobar = "xyz";
Collect with toList() and toSet() Elements from a Stream can be easily collected into a container by using the Stream.collect operation: System.out.println(Arrays .asList("apple", "banana", "pear", "kiwi", "orange") .stream() .filter...
RelativeLayout is a ViewGroup that displays child views in relative positions. By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams. The value for each layout...

Page 1 of 145