tags:

views:

83

answers:

2

Is there any mechanism in C# that allows one to define and declare an Enum variable in the same line like so:

public class ClassWithEnumMember
{
    public Enum Type { TYPE1, TYPE2, TYPE3 } = TYPE1;
}
+4  A: 
public enum Foo { Bar, Baz }; public Foo myField = Foo.Bar;

All neatly on one line!

Matti Virkkunen
While I suspect the poster meant one statement when saying one line, I like this solution. You get an up vote.
Matthew Ferreira
I know what the poster meant. However I don't see why he'd want to do what he's trying to do.
Matti Virkkunen
Indeed. Hence the answer that I gave.
Matthew Ferreira
A: 

This simplest answer is no. Why not just make it two lines?

Matthew Ferreira
I was looking for a solution similar to declaring structs in C without typedef-ing them first.
Rire1979
"I can do this in C" is often a reason *not* to allow it in my language.
Jay Bazuzi
@Jay Bazuzi, good point. C# is excellent in preventing bad design ideas.
Al Bundy