0

C# で初めての UI プログラムを作成しているので、いくつかの問題に直面しています。
2 つのクラス ( Country、 ) があると仮定して、前に作成された An にCity新しいCountryオブジェクトをそれぞれ設定し、次のように名前を付けます。ArrayListCountryList

public static ArrayList CountryList = new ArrayList();

Country c1 = new Country(string name); // Creating Country object

CountryList.Add(c1); // Store the Object c1 in ArrayList

すべてCountryに独自のものがあるため、すべてのオブジェクトをまとめて格納する をCities作成することはできません! 次に、 Sub-ArrayList のようなものが欲しいです。ArrayListCity
ArrayList

4

2 に答える 2

3

これはどう?

public class City
{
  public string Name {get; set;}
}

public class Country 
{ 
  public string Name {get; set;}

  public List<City> Cities {get; set;}
}
于 2012-05-04T16:49:10.007 に答える
1

国を文字列にしないで、オブジェクトにしてください。

public class Country
{
   public string Name {get; set;}
   public IList<string> Cities {get; set;}
}

次に、あなたが持っているだろう

Country country = new Country{Name = "England"};
country.Cities.Add("London");
CountryList.Add(country);
于 2012-05-04T16:49:26.867 に答える