在第二个国家/地区内添加地方标签

时间:2014-10-20 02:20:08

标签: c# wpf class dictionary

如果我一直在研究这个问题,我之前得到了一些帮助,并且用户说最好使用Dictionary来存储我的CountryPlaces

所以我创建了Dictionary

Dictionary<string, NewCountryClass> NTCD = new Dictionary<string, NewcountryClass>();

当用户单击该按钮时,它将触发此类,我希望它在运行时在newCountryClass内创建Dictionary的实例。它会添加newCountryTitle.Country的字符串,然后添加Class

public void AddCountryCollection()
{

    newCountryClass = new NewCountryClass(newCountry,"");
    Collections.Add(newCountryClass);
    NTCD.Add(newCountryClass.Country, newCountryClass);
}

因此,假设用户已添加在运行时创建此Country的{​​{1}},并且他们已添加4 Dictionary,但现在想要返回并添加{ {1}}标记在第二个国家/地区内。

这是Countries

Place

如果他们已经创建了4,并且他们想要将newCountryClass添加到他们创建的第二个 private string _country; public string Country { get { return _country; } set { if (_country.Equals(value)) return; _country= value; RaisePropertyChanged(() => Country); } } private ICollection<string> _places; public ICollection<string> Places { get { if (_places== null) _places= new ObservableCollection<string>(); return _places; } set { if (value == _places) return; _places= value; RaisePropertyChanged(() => Places); } } 内的列表中,我该如何找到它?

1 个答案:

答案 0 :(得分:0)

我找到了答案,我只是使用我存储的密钥:

NTCD["GER"].Places.Add("New Place inside GER");

如果我只想知道第二个,请选择List<NewCountryClass>并使用foror以索引进行迭代,然后选择OrderedDictionary。它将对象键,对象值作为参数添加,我可以通过NTCD[3]访问它。