c# - Predicates and OrderBy , Func -


I understand that the representatives who take the bool back and take generic parameters, I understand That's when I say:

  mycustomer => Mycustomer.fullname == 1  

This really means:

  representative (customer mycustomer) {mycustomer.fullName == "John"; }  

When I pass this lambda expression I am passing:

Public Representative Ball Criteria & lt; T & gt; (T value) which is originally called illumination

but what I do not understand, it means that when I mycustomer => Mycustomer.fullname

I say customers.OrderBy (mycustomer => mycustomer.fullname);

How do I implement something like OrderBy ? How do I tell any method, which is to take action on the property! Like the previous example?

As an example, there is one case, I want to make a method that receives all the values ​​of the collection of a specific property:

  list & lt; String & gt; Mylist = customers.GetPropertyValues ​​(cus => cus.Fullname);  

Thanks in advance.

function & lt; Teleman, TKA & gt; is used by a IComparer & lt; TKey & gt; , which is used internally in OrderedEnumerable to sort items when you do:

  var Item = myList.OrderBy (i = & gt; i.SomeProperty);  

command unformatted type a IComparer & lt; TKey & gt; Built internally In the above example, if i.SomeProperty was a string , then it would be IComparer & lt; String & gt; Will make an example of and then sort these items into the SomeProperty member

on the source using that compressor.

In my last case:

  list & lt; String & gt; Mylist = customers.GetPropertyValues ​​(cus => cus.Fullname);  

You do this :

  var names = customers.Select (c => c.Fullname) ;  

A countdowner of the string names will return select method, Func & lt; TSource, TResult & gt; The is used to select the target element to be added in the result.

You can do it yourself to repeat:

  public static IEnumerable & lt; TMember & gt; GetPropertyValues ​​& lt; TSource, TMember & gt; (This IEnumerable & lt; TSource & gt; enumerable, function & lt; TSource, TMember & gt; selector); throw the new ArgumentNullException ("enumerable") {if (enumerable == null); Foreign Currency (TSOSR Item in NSA Merit) (Return Selector (Item);}}  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -