获取枚举数据值 [英] Get Enum Data Values

查看:91
本文介绍了获取枚举数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用枚举数据类型如何获取It的值??

我的代码是

I m using enum data types how to get value of It???

My code Is

public  class clsTabs
{
    public clsTabs()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public  enum TabControls
    {

        PersonalProfile=1,
        Address=2,
        NextOFKin=3,
        Dependents=4,
        Education=5,
        Experience=6,
        Reference=7,
        Documents=8,
        EmploymentCategory=9,



    }


}





int i= ((enum)clsTabs.TabControls.Address;

推荐答案

尝试

Try

int i = (int)clsTabs.TabControls.Address;



强制转换(int)应该是您要返回的类型,而不是数据类型.



The cast (int) should be of the type that you want returned, not the type of the data.


为了使用正确的命名法,枚举的成员称为顺序".要获取枚举数的序数值,只需将其转换为适当的类型(通常为int)即可.

我还针对不可信数据中的枚举数的设置写了一个提示/技巧:

从有问题的数据源中设置枚举器 [
In the interest of using correct nomenclature, the member of an enumuration is called an "ordinal". To get the ordinal value of the enumerator, simply cast it to the appropriate type (normally an int).

I also wrote a tip/trick regarding the setting of enumerators from untrusted data:

Setting Enumerators From Questionable Data Sources[^]


使用

use

<br />
int i =Convert.ToInt32(clsTabs.TabControls.Address);<br />



问候

Abraheem Abulubbad



regards

Abraheem Abulubbad


这篇关于获取枚举数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆