I have an object with the following structure: (pseudocode)
class Client
{
- int ID
- int? ParentID
- string Name
- datetime CreateDate
- int ACClientID
- List <Client> Clients }
I want to loop through the whole nested structure using a recursive foreach, to set the ACClientID of ALL to a value.
I know that the enumerator in a foreach is immutable so the following doesn't work:
private static bool AssignToChildren(ref ATBusiness.Objects.Client client, int ACClientID)
{
client.ACClientID = ACClientID;
foreach (ATBusiness.Objects.Client child in client.Clients)
{
AssignToChildren(ref child, ACClientID);
}
}
What would be the most efficient way of achieving my goal?
PS: I will not be adding or removing from the structure, merely setting one attribute for every nested Client object.
[edit] I've looked at http://stackoverflow.com/questions/759966/what-is-the-best-way-to-modify-a-list-in-a-foreach but it does not provide me with the answer I need.