CoolArchTek CoolArchTek - 29 days ago 15
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

Just try with this.

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