Like dbaseman's answer (and AKX's comment), I would use Cast
:
IEnumerable<MyClass> vats = here.All().Cast<MyClass>();
You will need the using
directive for LINQ:
using System.Linq;
at the top of the file. It looks like you don't have this if the Select
method is not recognized.
Note that this assumes that each value is indeed a MyClass
reference.
EDIT: if you want to have access to values by index, I would recommend using ToList
:
List<MyClass> vats = here.All().Cast<MyClass>().ToList();
While ToArray
will work too, I personally prefer lists over arrays in most cases, as they are more flexible.
EDIT: It looks like your results are actually full of ExpandoObject
. You will need to create a new instance of MyClass
from each element, for example.
List<MyClass> vats = here.All() .Select(item => new MyClass(item.Name, item.Value)) .ToList();
or perhaps:
List<MyClass> vats = here.All() .Select(item => new MyClass { Name = item.Name, Value = item.Value, }) .ToList();
This is just an example that I would not expect to work right away - we cannot do anything better, because we do not know anything about how your results will return.
It sounds like you're on your head, I'm afraid.
source share