November 2017
Intermediate to advanced
800 pages
30h 51m
English
Let's define a method that only includes names that are longer than four characters.
Statically import the Console class, and then add the following method to the Program class:
static bool NameLongerThanFour(string name)
{
return name.Length > 4;
}
Pass the method's name into the Func<string, bool> delegate, and then loop through the query items, as shown in the following code:
var query = names.Where(new Func<string, bool>(NameLongerThanFour)); foreach (string item in query)
{
WriteLine(item);
}
In the Main method, call the LinqWithArrayOfStrings method, as shown in the following code:
static void Main(string[] args){ LinqWithArrayOfStrings();}
Run the console application and view the output:
Michael Dwight Angela ...
Read now
Unlock full access