0
如果我一直在正确研究此问题,我之前得到了一些帮助,并且有一位用户表示,使用Dictionary
来存储我的Country
和Places
将会很好。在第二个国家内添加地方标签
所以我创造我Dictionary
:
Dictionary<string, NewCountryClass> NTCD = new Dictionary<string, NewcountryClass>();
当用户点击该按钮,我想它在运行时创建的Dictionary
内的newCountryClass
一个实例,就会触发这个类。它会添加将是newCountryTitle.Country
,然后是Class
的字符串。
public void AddCountryCollection()
{
newCountryClass = new NewCountryClass(newCountry,"");
Collections.Add(newCountryClass);
NTCD.Add(newCountryClass.Country, newCountryClass);
}
因此,可以说用户已经增加了其创造了这个Dictionary
在运行时Country
,和他们增加了4 Countries
,但现在想回去,并添加第二个国家内Place
标签。
这是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);
}
}
如果他们创造4,他们希望到Place
添加到列表中的第二一个他们创造的是Country
里面,我怎么会发现呢?
考虑使用[OrderedDictionary](http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary(v = vs.110).aspx),看起来像是唯一的方法。但它不是通用的。性能可能会比通常的普通字典稍差。 – 2014-10-20 02:42:32
另外这个问题不应该这么长。它应该只是一些线*** ***。为什么?问题只是***如何获得字典***的第二个元素。就这样。问这样的问题将会使许多用户(包括专家)忽略这个问题(我们通常害怕长期问题)。 – 2014-10-20 02:50:13