string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay", "Maya" }; int[] number = { 1, 5, 6, 8, 20, 15, 34, 67, 98, 12, 23 }; var num = number.Where(n => n > 100).FirstOrDefault(); //num=0 var numm = number.Where(n => n > 100).First(); //will give an error var nummm = number.Where(n => n > 100).DefaultIfEmpty(1).First(); //nummm=1 var nam = names.Where(n => n.StartsWith("z")).FirstOrDefault();//nam=null var name = names.Where(n => n.StartsWith("M")).SingleOrDefault(); //will give an error because two values found with “M”
Friday, April 25, 2014
using First, FirstOrDefault, DefaultIfEmpty, Single, SingleOrDefault
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment