Enum wiht numeric values

  • Thread starter Thread starter Krish
  • Start date Start date
K

Krish

I want to have an enum that has a list of numeric values. How do I
achieve this?

Something like this ...

Public Enum AllowedNumbers
{
111,
222,
333,
444,
555
}

I can only have


Public Enum AllowedNumbers
{
AllowedValue1 = 111,
AllowedValue2 =222,
AllowedValue3 =333,
AllowedValue4 =444,
AllowedValue5 =555
}

Is there any way I can achieve this?
 
I want to have an enum that has a list of numeric values. How do I
achieve this?

Why do you want an enum if you're not going to use the names? Wouldn't
an array work instead?

int[] allowedNumbers = {111,222,333,444,555};


Mattias
 
Hello Krish,
Something like this ...

Public Enum AllowedNumbers
{
111,
222,
333,
444,
555
}

It looks to me as if you're looking for a language feature similar to the
sets in Pascal.... that is not what enums are about. PowerCollections
(http://www.wintellect.com/PowerCollections.aspx) has an implementation of
Set<T> and Bag<T> classes, and there are certainly other collection
libraries that do similar things, but there's no C# language feature for
this.


Oliver Sturm
 
I want to have an enum that has a list of numeric values. How do I
achieve this?

Why do you want an enum if you're not going to use the names? Wouldn't
an array work instead?

int[] allowedNumbers = {111,222,333,444,555};

Mattias

I dont think an array can work in my case.
What I need is to declare a variable of type enum and that enum can
have a list of numeric values.
Which means the variable can have one of the list of (numeric) values
ie my variable can have 111 or 222 or 333 or 555. How can we use array
in this case.

Thanks in advance ofr your help
 
Back
Top