如果我有一个 SortedList<int, MyClass>
,我想要返回该类的属性的新的IEnumerable<T>
,我该怎么做?
我尝试过使用 SortedList.Select(x=>x.MyProperty, x.AnotherProperty)
,但它不起作用。
谢谢。
var result = SortedList.Select(x => new {
x.Value.MyProperty,
x.Value.AnotherProperty
});
或者如果您想在当前方法的范围之外使用结果,您可以定义一个自定义类型:
IEnumerable<MyType> result = SortedList.Select(x => new MyType {
Prop1 = x.Value.MyProperty,
Prop2 = x.Value.AnotherProperty
});