Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何静态分配字典值_C#_Collections - Fatal编程技术网

C# 如何静态分配字典值

C# 如何静态分配字典值,c#,collections,C#,Collections,如果值是另一个类/对象,如何静态地为字典赋值。如以下链接所示: 使用可设置SettingItem对象的值 使用可设置SettingItem对象的值 必须初始化对象: public Dictionary<SettingKey, SettingItem> List = new Dictionary<SettingKey, SettingItem>() { {SettingKey.userDBName, new SettingItem { theValue =

如果值是另一个类/对象,如何静态地为字典赋值。如以下链接所示:

使用可设置SettingItem对象的值

使用可设置SettingItem对象的值


必须初始化对象:

public Dictionary<SettingKey, SettingItem> List =
    new Dictionary<SettingKey, SettingItem>()
{
    {SettingKey.userDBName, new SettingItem { theValue = "user-name", theID  = 1 }},
    {SettingKey.realName,   new SettingItem { theValue = "real-name", theID  = 2 }}   
};

必须初始化对象:

public Dictionary<SettingKey, SettingItem> List =
    new Dictionary<SettingKey, SettingItem>()
{
    {SettingKey.userDBName, new SettingItem { theValue = "user-name", theID  = 1 }},
    {SettingKey.realName,   new SettingItem { theValue = "real-name", theID  = 2 }}   
};
public Dictionary<SettingKey, SettingItem> List =
    new Dictionary<SettingKey, SettingItem>()
{
    {SettingKey.userDBName, new SettingItem { theValue = "user-name", theID  = 1 }},
    {SettingKey.realName,   new SettingItem { theValue = "real-name", theID  = 2 }}   
};