日期:2014-05-18  浏览次数:20892 次

数字如何转换成enum
C# code

    public enum ModuleType
    {
        None = 0,
        DiscsystemManager = 1,
        ImageTextInfoManager = 2
    }



数据库里面有个tinyint的字段,存着0或者1或者2
如何把它们读出来后赋给一个ModuleType类型的对象

------解决方案--------------------
C# code
public enum ModuleType
{
    None = 0,
    DiscsystemManager = 1,
    ImageTextInfoManager = 2
}
private void button2_Click(object sender, EventArgs e)
{
    ModuleType mt = (ModuleType)0;
    Console.WriteLine(mt);
}

------解决方案--------------------
ModuleType m = (ModuleType)2;
------解决方案--------------------
探讨
ModuleType m = (ModuleType)2;

------解决方案--------------------
数据库表A,假设C#实体名也为A,字段tinyint;则
C# code

public enum ModuleType
{
    None = 0,
    DiscsystemManager = 1,
    ImageTextInfoManager = 2
}
private void button2_Click(object sender, EventArgs e)
{
    ModuleType mt = (ModuleType)(A.tinyint);
    Console.WriteLine(mt);
}