Skip to main content

Posts

Showing posts from June, 2017

LINQ in Detail

LINQ in Detail https://www.dotnettricks.com/learn/linq/sql-joins-with-csharp-linq Single() vs First() Single will throw an exception if it finds more than one record matching the criteria. First will always select the first record from the list. If the query returns just 1 record, you can go with  First() . Both will throw an  InvalidOperationException  exception if the collection is empty. Alternatively you can use  SingleOrDefault() . This won't throw an exception if the list is empty _____________________________________________________________________________ Offtype:  Use OfType operator to filter the above collection based on each element's type ex:  IList mixedList = new ArrayList (); mixedList.Add(0); mixedList.Add( "One" ); mixedList.Add( "Two" ); mixedList.Add(3); mixedList.Add( new Student() { StudentID = 1, StudentName = "Bill" }); var stringResult = from s in mixedList.OfType< string >() ...