Enum to Dictionary in C#

前端 未结 10 2039
攒了一身酷
攒了一身酷 2020-12-02 15:10

I have searched this online, but I can\'t find the answer I am looking for.

Basically I have the following enum:

public enum typFoo : int
{
   itemA         


        
10条回答
  •  庸人自扰
    2020-12-02 15:55

    If you need only the name you don't have to create that dictionary at all.

    This will convert enum to int:

     int pos = (int)typFoo.itemA;
    

    This will convert int to enum:

      typFoo foo = (typFoo) 1;
    

    And this will retrun you the name of it:

     ((typFoo) i).toString();
    

提交回复
热议问题