C# 将列表的字符串属性转换为枚举

C# 将列表的字符串属性转换为枚举,c#,dictionary,enums,C#,Dictionary,Enums,如何将列表字母字符串属性大小正确转换为枚举 Customer.Letter.Size是字符串类型 Customer.Letter[i].Size = (BusinessObjects.CONSTANTS.E_Letters)BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size];//i variable declared in an for loop 这是我的枚举: public enum E_Size { small = 1,

如何将列表字母字符串属性大小正确转换为枚举

Customer.Letter.Size是字符串类型

Customer.Letter[i].Size = (BusinessObjects.CONSTANTS.E_Letters)BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size];//i variable declared in an for loop
这是我的枚举:

public enum E_Size {
    small = 1,
    medium = 2,
    big = 3
}
这是我的字典:

    public static Dictionary<string, E_Size> dict = new Dictionary<string, E_Size> {
        { "small", E_Size.small},
        { "medium", E_Size.medium},
        { "big", E_Size.big}
    };
publicstaticdictionary dict=新字典{
{“小”,E_Size.small},
{“中等”,E_Size.medium},
{“大”,E_Size.big}
};

为什么不使用标准的
Enum.Parse

  String source = "small"; 
  // E_Size.small 
  E_Size size = (E_Size) (Enum.Parse(typeof(E_Size), source));
反向转换(从
E_Size
String


为什么不使用标准的
Enum.Parse

  String source = "small"; 
  // E_Size.small 
  E_Size size = (E_Size) (Enum.Parse(typeof(E_Size), source));
反向转换(从
E_Size
String


为什么不使用标准的
Enum.Parse

  String source = "small"; 
  // E_Size.small 
  E_Size size = (E_Size) (Enum.Parse(typeof(E_Size), source));
反向转换(从
E_Size
String


为什么不使用标准的
Enum.Parse

  String source = "small"; 
  // E_Size.small 
  E_Size size = (E_Size) (Enum.Parse(typeof(E_Size), source));
反向转换(从
E_Size
String


转换为字符串,而不是枚举:

Customer.Letter[i].Size = BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size].ToString();

转换为字符串,而不是枚举:

Customer.Letter[i].Size = BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size].ToString();

转换为字符串,而不是枚举:

Customer.Letter[i].Size = BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size].ToString();

转换为字符串,而不是枚举:

Customer.Letter[i].Size = BusinessObjects.CONSTANTS.dict[Customer.Letter[i].Size].ToString();

看起来不错。哪里有问题?获取错误:无法将类型“BusinessObjects.CONSTANTS.E_Size”隐式转换为“string”看起来正常。哪里有问题?获取错误:无法将类型“BusinessObjects.CONSTANTS.E_Size”隐式转换为“string”看起来正常。哪里有问题?获取错误:无法将类型“BusinessObjects.CONSTANTS.E_Size”隐式转换为“string”看起来正常。哪里有问题?获取错误:无法将类型“BusinessObjects.CONSTANTS.E_Size”隐式转换为“string”