Linq能用来查询自定义点类吗 如Cpeople解决办法
Linq能用来查询自定义点类吗 如Cpeople
如题,代码是这样写的,但是提示为找到类中Orderby的实现
如果定义一个CList列表存储CPerson对象可以用Linq查询,但是我自定义的Cpeople类就不行,为啥呢
------解决方案--------------------
我看到
如题,代码是这样写的,但是提示为找到类中Orderby的实现
- C# code
public class CPeople : DictionaryBase, ICloneable { public new IEnumerator GetEnumerator() { foreach (object person in Dictionary.Values) yield return (CPerson)person; } } CPeople pl; IEnumerable<CPerson> sortedPeple = from CPerson in pl orderby CPerson.Name.Length, CPerson.Name select CPerson; foreach (CPerson person in sortedPeple) { ListViewItem item = listView.Items.Add(person.Name); item.SubItems.Add(person.Age.ToString()); }
如果定义一个CList列表存储CPerson对象可以用Linq查询,但是我自定义的Cpeople类就不行,为啥呢
------解决方案--------------------
我看到
- C# code
public new
------解决方案--------------------
参考:
http://blog.****.net/q107770540/article/details/6010387
------解决方案--------------------
另外,还要实现这个INTERFACE。或者
IEnumerable<CPerson> sortedPeple =
from CPerson x in pl
orderby x.Name.Length, x.Name
select x;
也行。问题是因为IEnumerable.current只返回object, 编译器无法确定x的类型
------解决方案--------------------如需要阅读该回复,请登录或注册****!