一个提醒...such as implement System.Collections.Generic.IComparer<T>
- Like this:
1 L.Sort(delegate(int a, int b)
2 {
3 return (b - a);
4 });
The same as: L.Sort((a,b) => b-a);
If it's not a List<T>
We can cast it as:
1IEnumerable<int> myUsers = al.Cast<int>();
Then can use linq to do the things we need with myUsers
But sometimes this may throw exceptions...because not every item can cast to the TResult
Then we can use ofType<T>....
It will ignore the items which can't cast to TResult
2. Also can do it like this:
1 DAL demo = new DAL("");
2 L.Sort(demo.Compare);
2 L.Sort(demo.Compare);
with the DAL below:
1 class DAL : System.Collections.Generic.IComparer<int>
2 {
3 IComparer 成员
11 }
2 {
3 IComparer
11 }