Groups | Blog | Home
all groups > c# > may 2004 >

c# : Enumeration sets


Nitin Koshy
5/17/2004 11:11:03 PM

Please tell me there is an option for sets of enumeration in c# !?

eg : enum DataKind {dkSimple, dkComplex, dkCool
<DataKindSet> = Set of DataKind //Delphi style thoug

DataKindSet VariableofDataKindSet = new DataKindSet(dkSimple, dkCool)

No ?
Alternatives please

-Niti
Chris R. Timmons
5/18/2004 12:23:52 AM
"=?Utf-8?B?Tml0aW4gS29zaHk=?=" <nitinkoshy@mail.com> wrote in
news:75455C27-554C-4696-89F8-599E78D71810@microsoft.com:

[quoted text, click to view]

http://www.codeproject.com/csharp/Sets.asp

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
Nitin Koshy
5/18/2004 1:56:03 AM
Cheers Chris...looks interesting

I was thinking on using bit fields directly..
enum DataKind {dkSimple = 1, dkComplex = 2, dkCool = 4}

then do bitwise operations to manipulate the set, wherein the set itself could be just integer variables
int aSet = ((int)DataKind .dkSimple | (int)DataKind .dkCool ....et

Chris R. Timmons
5/18/2004 2:45:42 AM
"=?Utf-8?B?Tml0aW4gS29zaHk=?=" <nitinkoshy@mail.com> wrote in
news:E0AD8466-7B07-44E1-AE45-30A8A81F4398@microsoft.com:

[quoted text, click to view]

Yes, that can be done by using the FlagsAttribute:

[Flags]
enum DataKind {dkSimple = 1, dkComplex = 2, dkCool = 4};

int aSet = (int) (DataKind.dkSimple | DataKind.dkComplex);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
AddThis Social Bookmark Button