How to use a lambda expression in Enumerable.Distinct()?
How to use a lambda expression in Enumerable.Distinct()?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Aryan Kumar
19-Aug-2023Sure, I can help you with that.
To use a lambda expression in
Enumerable.Distinct(), you need to pass the lambda expression as the predicate parameter to theDistinct()method. The predicate parameter is a function that takes two elements of the sequence as its parameters and returns a boolean value. TheDistinct()method will return a sequence that contains only the elements of the original sequence for which the predicate returnstrue.Here is an example of how to use a lambda expression in
Enumerable.Distinct():C#
In this example, the lambda expression takes two integers as its parameters and returns a boolean value. The lambda expression returns
trueif the two integers are not equal, andfalseif the two integers are equal. TheDistinct()method will return a sequence that contains only the elements of the original sequence for which the predicate returnstrue.