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