Basically I have a method that is passed a list of custom objects. I'm using C#. Each of these contains a name and another list of other custom objects, I'll call these subObjects. These each have a name and a list of strings. I need to loop through all the strings, but keep track of the names of the parent object and subject for error logging purposes. Is there a cleaner, nicer way to do this than nesting foreachs?
foreach (var obj in listOfObjects)
{
foreach (var subObj in obj.subObjects)
{
foreach (var aString in subObj.strings)
{
if (some condition applies)
{
//log error that includes obj, subObj, and subSubObj names, and aString.
}
}
}
}
ifblock?subobj.stringswithsubObj.strings)so it compiles. :) I don't see any problem with this structure. It does what it has to. The only problem may be if inside thatifyou have to exit from the outerforeach, which would require a flag or a beautifulgoto. ;)