Similar to dbaseman's answer (and AKX's comment) I'd use Cast
:
IEnumerable<MyClass> vats = here.All().Cast<MyClass>();
You'll need a using
directive for LINQ though:
using System.Linq;
at the top of your file. It sounds like you haven't got that if the Select
method isn't recognized.
Note that this assumes that each value really is a MyClass
reference.
EDIT: If you want to be able to access the values by index, I'd recommend using ToList
:
List<MyClass> vats = here.All().Cast<MyClass>().ToList();
While ToArray
would work too, I personally favour lists over arrays in most cases, as they're rather more flexible.
EDIT: It sounds like your results are actually full of ExpandoObject
. You'll need to create a new instance of MyClass
from each item, e.g.
List<MyClass> vats = here.All()
.Select(item => new MyClass(item.Name, item.Value))
.ToList();
or possibly:
List<MyClass> vats = here.All()
.Select(item => new MyClass {
Name = item.Name,
Value = item.Value,
})
.ToList();
That's just an example, which I wouldn't expect to work straight away - we can't do any better than that as we know nothing about how your results are actually being returned.
It does sound like you're in over your head here, I'm afraid.