Advertisement
Guest User

enum search by index

a guest
Apr 24th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. private enum Combovalues
  2. {
  3. BezeichnungA = 1,
  4. BezeichnungB = 4,
  5. BezeichnungC = 60
  6. }
  7.  
  8. public void SomeMethod()
  9. {
  10.     Combovalues combovalue = Combovalues.BezeichnungB;
  11.     int comboValue = (int)combovalue;
  12.     string combovalueName = combovalue.ToString();
  13. }
  14.  
  15. public Combovalues GetCombovalue(int i)
  16. {
  17.     string name = Enum.GetName(typeof (Combovalues), i);
  18.     if (null == name) throw new Exception();
  19.     return (Combovalues)Enum.Parse(typeof (Combovalues), name);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement