If I have a SortedList<int, MyClass开发者_StackOverflow中文版>
and I want to return a new IEnumerable<T>
of properties from that class how do I do that?
I have tried SortedList.Select(x=>x.MyProperty, x.AnotherProperty)
but it doesnt work.
Thanks.
You could return an anonymous object:
var result = SortedList.Select(x => new {
x.Value.MyProperty,
x.Value.AnotherProperty
});
Or if you want to use the result outside of the scope of the current method you could define a custom type:
IEnumerable<MyType> result = SortedList.Select(x => new MyType {
Prop1 = x.Value.MyProperty,
Prop2 = x.Value.AnotherProperty
});
精彩评论