Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I m using enum data types how to get value of It???

My code Is

C#
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,



    }


}


C++
int i= ((enum)clsTabs.TabControls.Address;
Posted

Try

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


The cast (int) should be of the type that you want returned, not the type of the data.
 
Share this answer
 
Comments
Luc Pattyn 4-May-10 9:56am    
Hi Henry
just testing comment feature
Henry Minute 4-May-10 9:59am    
Hi, Luc. It seems to have worked.
Luc Pattyn 4-May-10 10:23am    
???
Ankur\m/ 8-May-10 0:55am    
Luc, you pointed out a bug about the third comment, lets see if it's the same after 3rd comment.
Added---- I can edit it.
Luc Pattyn 8-May-10 14:16pm    
Correction: yes I can edit them, however the edit box gets preloaded with the content of an arbitrary comment, not necessarily the one I want to edit.
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[^]
 
Share this answer
 
use

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


regards

Abraheem Abulubbad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900