CoolArchTek CoolArchTek - 1 year ago 209
C# Question

Querying IList using LINQ

Is foreach is the only option to get the property values of an object? (if I store that in var type)

IList<SampleClass> samples = GetIList();
var onesample = samples.Select(p => p.Propy == "A").FirstOrDefault();

do I need to loop through 'onesample' to get the values using foreach or any better way?

Answer Source

Just try with this.

IList<SampleClass> samples = GetIList();
SampleClass onesample = samples.FirstOrDefault(p => p.Propy == "A");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download