Lambda expressions examples

29/09/2012 18:38

//Get termstore groups count with 'groupName

var count = termStore.Groups.Count(grp => grp.Name.Equals(groupName));

 

var MySubCollection = MyCollection.Where(x => x.IntegerProperty > 5);

 

 

(input parameters) => expression

 

(x, y) => x == y

 

(int x, string s) => s.Length > x

 

() => SomeMethod()

 

 

   // Data source. 
        int[] scores = { 90, 71, 82, 93, 75, 82 };

        // The call to Count forces iteration of the source 
        int highScoreCount = scores.Where(n => n > 80).Count();

        Console.WriteLine("{0} scores are greater than 80", highScoreCount);

        // Outputs: 4 scores are greater than 80  

 

 Assert.IsFalse(restrictedChars.ToList().Any(s => encoded.Contains(s)));

 if (acceptedPages.Any(p => CompareUri(p, fieldUrlValue) == 0))