I have a class that has two integers in it, for example A
and B
:
public class MyClass {
public int A { get; set; }
public int B { get; set; }
...other stuff...
}
I have a MyCollection
of type ObservableCollection<MyClass>
in code, and have a need to get an IEnumerable<int>
of ALL the values -- both A
's and B
's -- together in one list.
I have figured out how to do it with quite verbose code (significantly simplified to be only one level below for example purposes, but actually 3 levels of "from" calls and selecting values from within nested lists):
IEnumerable<int> intsA=
(from x in MyCollection
select x.A);
IEnumerable<int> intsB =
(from x in MyCollection
select x.B);
IEnumerable<int> allInts = intsA.Concat(intsB);
It seems like there should be a way to select both variables at the same time into the same IEnumerable<int>
. Obviously below doesn't work, but I'd love something like
IEnumerable<int> allInts = (from x in MyCollection select x.A, x.B);
Does something like this exist that is more elegant than what I have above?
I found how to select multiple values into an anonymous type here, but that doesn't make it into the same IEnumerable and still requires more code/processing to get the items out.
(BTW, using .NET 4.5.1, if that makes a difference.) Thanks!