enum , , enum, static public ( ). :
public class Country1
{
public static State State1 { get; } = new State("State 1");
public static State State2 { get; } = new State("State 2");
...
}
, Country1.State1, ? State , string. , , .
You can follow the same principle for implementing a long chain of objects: Planet.Continent.Country.State.Province.Town.Street.Hause..
You speak
Content will be saved in the dictionary Dictionary<Tuple<string, Type>, object>, where Types will be Countryand Country.States.
not to do. These are different types, which is a poor choice of key. If you need to list (find) states, just add another element to Country:
public static IEnumerable<State> States
{
get
{
yield return State1;
yield return State2;
...
}
}
Then finding something might be simple linq:
var stateAInCountry1 = ...Countries.OfType<Contry1>().Single().States.Single(o => o.Name == "A");
var countriesWithStateA = ...Countries.Where(o => o.States.Any(o => o.Name == "A"));
You do not know what problem you are solving by entering a dictionary, but you can initialize an additional data structure with the correct key, if you have provided the possibility of iteration with ease.
source
share