一个提醒...such as implement System.Collections.Generic.IComparer<T>
2009-08-17 00:25
399 查看
Like this:
1 L.Sort(delegate(int a, int b)
2IEnumerable<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{
7 return (y - x);
8 }
9
10 #endregion
11 }
1 L.Sort(delegate(int a, int b)
2IEnumerable<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{
7 return (y - x);
8 }
9
10 #endregion
11 }
相关文章推荐
- 使用泛型类型System.Collections.Generic.Icomparer &lt;T&gt; 需要一个类型参数
- MVC 无法将类型“System.Collections.Generic.List<AnonymousType#1>”隐式转换为“System.Collections.Generic.IList<Mvc3Modeltest.Models.Movie>”。存在一个显式转换(是否缺少强制转换?))
- [corefx注释说]-System.Collections.Generic.Stack<T>
- “System.Collections.Generic.IEnumerable<TestDAL.HistoryData>”不包含“ToList”的定义
- 《学习笔记》System.Collections.Generic 命名空间 HashSet<T>
- “System.Collections.Generic.IEnumerable<TestDAL.HistoryData>”不包含“ToList”的定义
- ForEach :对 System.Collections.Generic.List<T> 的每个元素执行指定操作
- 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数
- 无法将类型“System.Collections.Generic.IEnumerable<EmailSystem.Model.TemplateInfo>”隐式转换为“System.Collections.Generic.List<EmailSystem.Model.TemplateInf
- System.Collections.Generic.List<>是System.Collections.ArrayList的泛型实现
- System.Collections.Generic.List<T> 与 System.Collections.ArrayList
- NHibernate无法将类型“System.Collections.Generic.IList<T>”隐式转换为“System.Collections.Generic.IList<IT>
- “System.Collections.Generic.IEnumerable<decimal>”不包含“ToArray”的定义,并且找不到可接受类型为“System.Collections.Generic.IEnumerable<decimal>”的第一个参数的扩展方法“ToArray”
- System.Collections.Generic.IEnumerable<T>接口
- 无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“System.Collections.Generic.List<Ecology.Model.EnergyFlowGraph>”
- [corefx注释说]-System.Collections.Generic.Queue<T>
- - Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
- 实体类集合(List<Object>)根据实体类的一个或者多个属性对集合进行排序-Collections.sort
- IComparable<T> Vs. IComparer<T> System.Comparison<T>
- AsParallel \AsQueryable<T>().ToList() [System.ArgumentOutOfRangeException was unhandled" 索引超出范围。必须为非负值并小于集合大小]解决方法