1

In Visual Studio -- well, I am using Visual Studio 11 Beta, so that might be the issue -- I think I am coding enums ok. But while this works:

enter image description here

This does not work:

enter image description here

What is wrong?

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
xarzu
  • 8,657
  • 40
  • 108
  • 160

3 Answers3

11

Nothing to do with the VS11 beta. You just have to prefix with the enum name:

return TriangleType.error;
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
4

C# is a strong typed language. You are missing the enum name before the enum value. This should work:

return TriangleType.error;

and so on...

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
  • Talking of strong typing regarding C# enums is a bit misleading, especially given that you could return values outside the enum, too ;-) – Joey May 30 '12 at 09:20
2

If you wanted to do as in your first example and return an int you could cast the value and still use the enum "names", as in:

return (int)TriangleType.scalene;

See this other SO question for more information.

Community
  • 1
  • 1
McArthey
  • 1,614
  • 30
  • 62