How to do it...

  1. Create a console application and add a class called LambdaExample to the console application. Add a property to this class called FavThings:
        public class LambdaExample
{
public string FavThings { get; set; }
}
  1. In the console application, create a List<LambdaExample> object and add a few of your favorite things to this list:
        List<LambdaExample> MyFavoriteThings = new List<LambdaExample>();
LambdaExample thing1 = new LambdaExample();
thing1.FavThings = "Ice-cream";
MyFavoriteThings.Add(thing1);

LambdaExample thing2 = new LambdaExample();
thing2.FavThings = "Summer Rain";
MyFavoriteThings.Add(thing2);

LambdaExample thing3 = new LambdaExample();
thing3.FavThings = "Sunday morning snooze";
MyFavoriteThings.Add(thing3);
  1. Then, create an expression to return only the things starting with the string "Sum". Here, we would obviously expect to see Summer Rain as a result:
        var filteredStuff = MyFavoriteThings.Where(feature =>         feature.FavThings.StartsWith("Sum"));
  1. Place a breakpoint on the expression and run your application. When the code stops at the breakpoint, you can copy the lambda expression:
  1. Paste the lambda expression MyFavoriteThings.Where(feature => feature.FavThings.StartsWith("Sum")) into your Watch windows and change the string in the StartsWith method from Sum to Ice. You will see that the result has changed and now displays an Ice-cream string:
Note that if you are using Visual Studio 2017 RC, debugging lambda expressions will probably not work. You will receive anything from Internal error in the expression evaluator to a message stating Expression cannot contain lambda expression.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.251