eEhdsa

一个提醒...such as implement System.Collections.Generic.IComparer<T>

  1. 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);

 


with the DAL below:

 

 1    class DAL : System.Collections.Generic.IComparer<int>
 2    {
 3        IComparer 成员
11     }

 

 

posted on 2009-08-17 00:25  eEhdsa  阅读(191)  评论(0编辑  收藏  举报

导航