【发布时间】:2012-12-22 08:36:42
【问题描述】:
如何将值静态分配给字典,其中值是另一个类/对象。喜欢下面的链接:C#: How can Dictionary<K,V> implement ICollection<KeyValuePair<K,V>> without having Add(KeyValuePair<K,V>)?
class Settings
{
public Dictionary<SettingKey, SettingItem> List =
new Dictionary<SettingKey, SettingItem>()
{
{SettingKey.userDBName,{ theValue = "user-name", theID = 1 }},
{SettingKey.realName,{ theValue = "real-name", theID = 2 }}
};
}
enum SettingKey
{
userDBName,
realName
}
class SettingItem
{
public string theValue { get; set; }
public int theID { get; set; }
}
【问题讨论】:
标签: c# collections