Tag: icomparer

使用lambdaexpression式代替IComparer参数

在C#中,是否可以在方法调用中将一个lambdaexpression式作为IComparerparameter passing? 例如类似的东西 var x = someIEnumerable.OrderBy(aClass e => e.someProperty, (aClass x, aClass y) => { return x.someProperty > y.SomeProperty ? 1 : x.someProperty < y.SomeProperty ? -1 : 0; } ); 我不能完全得到这个编译,所以我不猜测,但似乎lambda和匿名代表之间的这种明显的协同作用,我觉得我必须做一些愚蠢的错误。 TIA

何时使用IComparable <T> Vs. 的IComparer <T>

我试图找出我需要实现哪些接口。 他们都基本上做同样的事情。 我什么时候可以使用一个呢?

在Linq OrderBy中使用自己的IComparer <T>

我有一个通用的 List<MyClass> 其中MyClass有一个属性InvoiceNumber ,它包含如下的值: 一分之二十零万零九百零六 二分之二十零万零九百零六 .. 十分之二十零万〇九百〇六 十一分之二十零万零九百零六 十二分之二十万○九百○六 我的清单是绑定到一个 BindingList<T> 它支持用linq进行sorting: protected override void ApplySortCore( PropertyDescriptor property, ListSortDirection direction) { _sortProperty = property; _sortDirection = direction; var items = this.Items; switch (direction) { case ListSortDirection.Ascending: items = items.OrderByDescending(x => property.GetValue(x)).ToList(); break; case ListSortDirection.Descending: items = items.OrderByDescending(x => property.GetValue(x)).ToList(); break; } this.Items = items; […]