System. linq. the Enumerable class provides many extension methods. Generally, the type of the IEnumerable <T> interface can be extended. For example, the OrderBy method is defined in the Enumerable class, this method is used to sort the sequence of target values based on a key value. The int [] type can have the OrderBy method.
The OrderBy method has two parameters: this IEnumerable <TSource> source, and Func <TSource, TKey> keySelector. Among them, Func is a TSource type parameter, which returns the delegate of the TKey type value. It must be said that this parameter can be written in multiple ways: 1,
1. directly use Lambda expressions:
1 int [] sets = {1, 3, 6, 4, 3, 8, 7 };
2 var subset = sets. OrderBy (int a) =>{ return ;});
3 foreach (var temp in subset)
4 {
5 console. write (temp );
6}
2. Use the anonymous method:
1 int [] sets = {1, 3, 6, 4, 3, 8, 7 };
2 var subset = sets. OrderBy (delegate (int a) {return ;});
3 foreach (var temp in subset)
4 {
5 console. write (temp );
6}
3. New delegate:
1 int key (int)
2 {
3 return;
4}
5
6 int [] sets = {1, 3, 6, 4, 3, 8, 7 };
7 var subset = sets. OrderBy (new Func <int, int> (key ));
8 foreach (var temp in subset)
9 {
10 console. write (temp );
11}
Any new delegate (new MyDelegate (…) required (......)) Generally, you can use the anonymous method (delegate (parameter ){......}), You can also use lambda expressions (parameters) =>{ function body }).