C#C
C#4y ago
Populus

Paradoxical initializers [Answered]

Two classes. Class Character and Class Guild.
Character has a field of Guild.
Guild has an array of Members composed of a Character[] array.

Wondering how to re-concile the constructors to allow for creation of one before the other.

Code attached:
public class Character
    {
        public string? Name { get; set; } // In-game identifier.
        public Guild? Guild { get; set; } // In-game guild identifier.

        public Character(string Name)
        { 
            this.Name = Name; 
        }

        public Character(
            string Name,
            Guild Guild,
            )
        {
            this.Name = Name;
            this.Guild = Guild;
        }
    }

public class Guild
    {
        public string? Name { get; set; } // Name of Guild. (i.e "chumbucket & Associates").
        public Character[]? Members { get; set; } // Array of characters.

        public Guild(string Name, Character[] Members)
        {
            this.Name = Name;
            this.Members = Members;
        }
    }
Was this page helpful?