I have a 3 classes:
Class 1:
public IEnumerable<double> Values;
public Class2 class2Instance;
Class2:
public string Name;
public Class3 class3Instance;
Class3:
public long Id;
public string Name;
Now I have got a huge collection of Class1, something like an IEnumerable<Class1>, and I have the Class3 Id. How can I use an efficient LINQ query to get all Class1 instances which are relevant to Class2 which matches with Class1 ID?
Well if you’ve only got a sequence of them, you’ve got to go through all of them:
If you need to do this regularly, you may want to build a
Dictionary<long, Class1>instead.(I’m assuming that neither
class2Instancenorclass3Instancecan be null. If they can, you’ll need to use code like Aducci’s.)