考虑下面的例子,我试图覆盖枚举值,以便能够解析枚举,而不仅仅是大写字母:
public enum Language
{
Heb,
Eng,
heb = Heb,
eng = Eng
}
class Program
{
static void Main(string[] args)
{
var e = "heb";
Language result;
Enum.TryParse(e, out result);
Console.WriteLine(result);
Console.WriteLine(result.ToString());
}
}
此示例返回:“Heb”“Heb”
另一方面,这个例子:
public enum Language
{
Heb,
Eng,
heb = Heb,
eng = Eng,
None
}
class Program
{
static void Main(string[] args)
{
var e = "heb";
Language result;
Enum.TryParse(e, out result);
Console.WriteLine(result);
Console.WriteLine(result.ToString());
}
}
返回 "heb" "heb"
任何想法为什么?