Získajte názov enum z hodnoty c#

Príklady kódu

2
0

získajte hodnotu enum c#

int something = (int) Question.Role;
1
0

c # získať názov zoznamu z hodnoty

string name=(weekdays)2;//returns weekdays which has value 2.Here weekdays is enum name
1
0

c # získajte hodnotu enum z reťazca

//This example will parse a string to a Keys value
Keys key = (Keys)Enum.Parse(typeof(Keys), "Space");
//The key value will now be Keys.Space
0
0

získať kľúč z c # enum pre konkrétnu hodnotu

enum myEnum { firstValue: 1, secondValue 2, thirdValue = 3};
string text = Enum.GetName(typeof(myEnum), 2); // text is "secondValue"
0
0

získajte názov enum z hodnoty c#

int enumValue = 2; // The value for which you want to get string 
string enumName = Enum.GetName(typeof(EnumDisplayStatus), enumValue);
0
0

c # získať hodnotu reťazca enum

using System;

public class GetNameTest {
    enum Colors { Red, Green, Blue, Yellow };
    enum Styles { Plaid, Striped, Tartan, Corduroy };

    public static void Main() {

        Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
    }
}
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................