Searcher
Searcher

Reputation: 1855

Error while defining enum structure.

I am creating class like this with enum.

 public class D
    {
        enum e { "one","two","three"};
    }

It is giving "identifier expected" compilation error. Whats wrong in this. is there any another structure.

Upvotes: 1

Views: 2119

Answers (5)

dtsg
dtsg

Reputation: 4459

You could do:

enum e
{
   One = 1,
   Two = 2,
   Three = 3
}

Upvotes: 0

Matten
Matten

Reputation: 17603

You can't have string enumerations in C#, for an example using attributes have a look at this article at codeproject.

You need to define your enum like

enum e
{
  One, Two, Three
}

Upvotes: 3

Mihir
Mihir

Reputation: 8734

Remove the quotes and try like this.

enum e{
one,
two,
three
};

Upvotes: 1

HatSoft
HatSoft

Reputation: 11201

public class D
    {
        enum e { one = 1, two = 2, three = 3};
    }

Upvotes: 1

dtsg
dtsg

Reputation: 4459

The answer is in the error message. You need to identify each of the values in the enum e.g.

 enum e
 {
   One = 1,
   Two = 2,
   Three = 3
 }

Upvotes: 2

Related Questions