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
  • 98,751
  • 30
  • 222
  • 258
xarzu
  • 8,127
  • 38
  • 103
  • 146

3 Answers3

10

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

return TriangleType.error;
McGarnagle
  • 98,751
  • 30
  • 222
  • 258
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
  • 36,757
  • 12
  • 82
  • 99
  • 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,584
  • 29
  • 59