Visual Studio 2015 has added the ability for developers to debug lambda expressions. This is a fantastic addition to the features of our favorite IDE. It allows us to check the results of a lambda expression on the fly and modify the expression to test different scenarios.
We will create a very basic lambda expression and change it in the Watch window to produce a different value.
CSharpSix
. Add a property to this class called FavoriteFeature
:public class CSharpSix { public string FavoriteFeature { get; set; } }
List<CSharpSix>
object and add a few of your favorite C# 6 features to this list:List<CSharpSix> FavCSharpFeatures = new List<CSharpSix>(); CSharpSix feature1 = new CSharpSix(); feature1.FavoriteFeature = "String Interpolation"; FavCSharpFeatures.Add(feature1); CSharpSix feature2 = new CSharpSix(); feature2.FavoriteFeature = "Exception Filters"; FavCSharpFeatures.Add(feature2); CSharpSix feature3 = new CSharpSix(); feature3.FavoriteFeature = "Nameof Expressions"; FavCSharpFeatures.Add(feature3);
"Ex"
string. Here, we would obviously expect to see exception filters as a result:var filteredFeature = FavCSharpFeatures.Where(feature => feature.FavoriteFeature.StartsWith("Ex"));
StartsWith
method. You will see that the result has changed to the "Nameof Expressions"
string:Being able to debug lambda expressions allows us to change and debug a lambda expression easily. This is something that was not possible in previous versions of Visual Studio. It is obviously of great importance to know this tip when working with these expressions.
Another point to note is that you can do the same thing from the Immediate window in Visual Studio 2015, as well as pinned variables from the lambda expression.
3.147.58.194