-2

Possible Duplicate:
Enums returning int value

I want to numerate "Stack", "Overflow" and "Stackoverflow". Therefore I use enumerate.

enum Status : int
{
     Stack = 1,
     Overflow = 2,
     StackOverflow = 3
}

But when I want to get value of Stack, I get "Stack".

int status = 0;
status = Status.Stack; //I want to assign 1 to status but Status.Stack returns "Stack"

How can I do it?

Community
  • 1
  • 1
Stack User
  • 1,378
  • 5
  • 19
  • 40
  • 1
    -1 Is it hard to [google](https://www.google.com/search?q=get+numeric+vslue+from+enum&rlz=1C1SKPL_enUA453UA453&sugexp=chrome,mod=14&sourceid=chrome&ie=UTF-8#hl=uk&pwst=1&rlz=1C1SKPL_enUA453UA453&sclient=psy-ab&q=c%23+get+numeric+value+from+enum&oq=c%23+get+numeric+value+from+enum&gs_l=serp.3..0i30.110038.111035.0.111516.3.3.0.0.0.0.124.322.1j2.3.0...0.0...1c.BAs9Fmuc_xg&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&fp=13173b19efa8ab06&biw=1920&bih=967) this? – Anatolii Gabuza Aug 15 '12 at 10:48
  • yes you are right @AnatoliiG but there were a problem for :int after that it is solved.. thanks for your quick reply – Stack User Aug 15 '12 at 10:53

1 Answers1

6

Just cast to int:

status = (int) Status.Stack;
jonnystoten
  • 7,055
  • 2
  • 28
  • 36