unisgned integers and global cases in C#

Complete

OSNN Addict
Joined
25 Aug 2005
Messages
94
I am used to C++ more than C#.

In C++ you have header files and you have the ability to declare states. For example, you can declare a series of unsigned integers to be for a variety of different states to later use in switch statements or if-then statements.

Since C# does not have the same sort of structure with header files, how would I impliment a simular functionality in C#?

The reason why I want to use UINT is because you can do that super cool bit-wise and and or with them. Remember those good ol' days? You could define four different conditions like this:

UINT state_001 2
UINT state_002 4
UINT state_003 8
UINT state_004 16

Then a variable can be any one state or any combination of states. To assign a variable a particular state, you do a bitwise and to the variable. To see if the variable was set to any of the states, you do a bitwise or.
How would that look like in Visual C#?
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
Why do you want to do this? What is the ultimate end goal?

Also, having initialised ints in C++ is a waste, rather use #define.

#define state0 (1 << 0)
#define state1 (1 << 1)
#define state2 (1 << 2)
#define state3 (1 << 3)

unsigned int myvar = state1 & state3

This way no memory needs to be allocated to store "dumb" numbers that are never going to change, and certain compiler optimisations can be used.
 

Members online

No members online now.

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR