I have the following:
class BaseType {
public Int32 Id { get; set; }
}
class Option : BaseType {
public String DisplayName { get; set; }
public String StoredValue { get; set; }
}
class Container {
public Collection<BaseType> Options;
}
Container c = new Container();
c.Options.add(new Option() { Id=1, DisplayName="Bob", StoredValue="aaaa"});
c.Options.add(new Option() { Id=2, DisplayName="Dora", StoredValue="bbbb"});
c.Options.add(new Option() { Id=3, DisplayName="Sara", StoredValue="cccc"});
Now, what I want to do is pull out the DisplayName of the specific option that matches StoredValue.
Previously, I’d iterate over the entire collection until I found a match. But, I’d rather have something that looked a bit better…
I got started with
var found = (from c in c.Options
where ...
And that’s where I’m stuck.
This should do it: