P
Peter
Hi
I am trying to get a handle on lambda expressions. I'm slowly beginning
to be able to read and understand them.
Quite often people use a single character to represent the parameter in
the expression. Is this considered good practice? At my stage it makes
it a little hard to understand the meaning.
Here is a simple example I found on a website:
List<string> names = new List<string>();
names.Add("Dave");
names.Add("John");
names.Add("Abe");
names.Add("Barney");
names.Add("Chuck");
string abe = names.Find(p => p.Equals("Abe"));
What is "p"? Does one read this by seeing that the variable "names" is
a "List<string>", and knowing that "Find" takes a "predicate" which
matches the type of the generic collection it is called on...?
Of course, real world examples can be slightly more complex, using
other classes and methods than "string" and "Equals" for example.
Thanks,
Peter
I am trying to get a handle on lambda expressions. I'm slowly beginning
to be able to read and understand them.
Quite often people use a single character to represent the parameter in
the expression. Is this considered good practice? At my stage it makes
it a little hard to understand the meaning.
Here is a simple example I found on a website:
List<string> names = new List<string>();
names.Add("Dave");
names.Add("John");
names.Add("Abe");
names.Add("Barney");
names.Add("Chuck");
string abe = names.Find(p => p.Equals("Abe"));
What is "p"? Does one read this by seeing that the variable "names" is
a "List<string>", and knowing that "Find" takes a "predicate" which
matches the type of the generic collection it is called on...?
Of course, real world examples can be slightly more complex, using
other classes and methods than "string" and "Equals" for example.
Thanks,
Peter