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? 3 2090
>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,44 4,555};
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
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. PowerCollection s
( http://www.wintellect.com/PowerCollections.aspx) has an implementation of
Set<Tand Bag<Tclasses, and there are certainly other collection
libraries that do similar things, but there's no C# language feature for
this.
Oliver Sturm
-- http://www.sturmnet.org/blog
On Feb 9, 11:06 am, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
wrote:
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,44 4,555};
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Glenn Venzke |
last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an
enum. Is it possible to pass the item name without the enum name in your
calling statement?
EXAMPLE:
public enum EnumName
FirstValue = 1
SecondValue = 2
ThirdValue = 3
|
by: Michael C |
last post by:
If a class inherits from another class, say Form inherits from control, then
I can assign the Form to a variable of type Control without needing an
explicit conversion, eg
Form1 f = new Form1();
Control c = f;
An enum value inherits from int but it doesn't get implicitly converted:
HorizontalAlignment h = HorizontalAlignment.Center;
|
by: Craig Klementowski |
last post by:
All,
I've installed the VS 2005 Beta 1 and was trying to build our current
product. I get a compile error when enum value is specified with
classname::enumname::enumvalue. Seems the compiler does not want the
enumname there anymore. This was not a problem with any previous versions of
VS. I could not find any help in any of my programming books or in MSDN. Can
anyone explain the reasons to me? Is this behavior to stay?
class...
|
by: Don |
last post by:
How do I get an Enum's type using only the Enum name?
e.g.
Dim enumType as System.Type
Dim enumName as String = "MyEnum"
enumType = ???(enumName)
|
by: Martin Engelhardt |
last post by:
Hi,
I want to use the following:
Class Test ...
Public Enum TestEnum as integer
Enum1 = 128
Enum2 = 256
End Enum
| |
by: Steven Nagy |
last post by:
So I was needing some extra power from my enums and implemented the
typesafe enum pattern.
And it got me to thinking... why should I EVER use standard enums?
There's now a nice little code snippet that I wrote today that gives me
an instant implementation of the pattern. I could easily just always
use such an implementation instead of a standard enum, so I wanted to
know what you experts all thought.
Is there a case for standard enums?
|
by: Zytan |
last post by:
Even with Option Strict On, which prevents an enum being set to an
Integer, you can still compare an enum to an integer without
complaint:
myEnum = 1 'fails
if (myEnum = 1) Then ... 'works
Is it possible to have strict type checking so strict that it prevents
all integer / enum interaction? I don't get why they would let this
one through.
|
by: At_sea_with_C |
last post by:
Consider the following code:
#include <stdio.h>
#define SOMEVAL 1234
enum tree_types { PINE = 10, BIRCH, LARCH, OAK = 100, MAPLE, ELM, WILLOW };
void print_val(enum tree_types tree)
{
printf("tree is: %d\n", tree);
|
by: tony_in_da_uk |
last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and
got a near-flippant response from someone who clearly didn't take the
time to consider the import. I replied, and it's still not in
evidence. Maybe it's my fault for having reacted with a little
annoyance, but anyway I'm tired of waiting days for moderators, have
had several posts not get through moderation at all which were
certainly not inappropriate, and an email from...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |