I have the following class:
public class TestClass {
public IList<TestClassDetail> TestClassDetails {
get { return _testClassDetails; }
}
private List<TestClassDetail> _testClassDetails = new List<TestClassDetail>();
public TestClass() {
this._testClassDetails = new List<TestClassDetail>();
}
}
public class TestClassDetail {
public TestClassDetail() {
this.Q = String.Empty;
}
public string Q { get; set; }
}
var TestClass a = <some code here to create the instace of a>
Now I need to be able to look at the object a, which in this case has 45 instance of TestClassDetail. I need to check each instance to see the first and only one which has a value of Q that is equal to “xx”. If it’s the 4th instance then I need to return 4.
Is this something that I could do with LINQ?
You can do something like this: