I am new to C# and taking my first course at a University. I think this is an issue with instantiation but here goes with what I am after.
I am wanting to get the value from te.ED w/o having to go through the multiple for each loops, as if the answer is "No" then there is no need to go through the loops and extract multiple data elements (not being shown). Is there a way to check that value BEFORE going through all of the for each loops?
Code is here
TR reply = service.track(request);
foreach (CTD ctd in reply.CTD)
{
foreach (TD td in ctd.TD)
{
if (td.Events != null)
{
foreach (TE te in td.Events)
{
if (te.TimestampSpecified)
{
//This is where the field I am after exists
if (te.ED == "YES")
Console.WriteLine("The answer is yes");
else
Console.WriteLine("The answer is no");
}
}
}
}
}
Per the comment from @Anis Programmer - I believe you are wanting to see the TD element from the class CTD. If that is the case - see below
[System.Xml.Serialization.XmlElementAttribute("TD")]
public TD[] TD {
get { return this.tdf; }
set { this.tdf = value; }
}
Per the answer from @Neel below - I am very close with the syntax
var result = reply.CTD.SelectMany(c1 => c1.TD)
.SelectMany(c2 => c2.Events.Select(c3 => c3.TimestampSpecified));
foreach (var ltr in result)
Console.WriteLine(ltr)
Now the issue is that the foreach loop makes two passes, and the value returned from both is True
What do I need to change in this syntax?
Enumerable.Firstis the answer, but hard to say without information on what code is expected to do.