Click here to Skip to main content
15,893,588 members
Home / Discussions / C#
   

C#

 
GeneralRe: Saving BMP/JPEG from Stream Pin
Gimpy19834-Jul-04 8:28
Gimpy19834-Jul-04 8:28 
GeneralDatagrid column header Pin
Member 5877032-Jul-04 6:33
Member 5877032-Jul-04 6:33 
Generalenum question Pin
Mikke_x2-Jul-04 6:27
Mikke_x2-Jul-04 6:27 
GeneralRe: enum question Pin
Werdna2-Jul-04 12:11
Werdna2-Jul-04 12:11 
GeneralRe: enum question Pin
Mikke_x2-Jul-04 12:49
Mikke_x2-Jul-04 12:49 
GeneralRe: enum question Pin
Colin Angus Mackay2-Jul-04 13:57
Colin Angus Mackay2-Jul-04 13:57 
GeneralRe: enum question Pin
Werdna2-Jul-04 14:38
Werdna2-Jul-04 14:38 
GeneralRe: enum question Pin
Colin Angus Mackay2-Jul-04 14:52
Colin Angus Mackay2-Jul-04 14:52 
enums and casting them to ints are not "bad". The explicit cast requirement is to make sure you think about what you are doing. On a number of projects I've worked on I've converted enums to/from ints frequently so that in the C# code the developer will not use invalid values and when it is stored in an int field in SQL Server it can be stored as an integer.

Werdna wrote:
See why it's bad?

Your example is bad, but the concept is not.

Taking your example, and extending it you get:
enum
{
One = 1,
Two = 2,
Three = 3
}

If you insert a new value you give it a new number. So long as you make sure you have no duplicates then everything works out fine. Using this approach also forces the developer to think about what is going on - something that sadly doesn't seem to happen very often.

Also, I use enums frequently when using interop because Native API calls use a defined set of flags but it receives them as an int, although in C/C++ there would be lots of #defines making up the defined set of values. To pass these enums in to Native API interop calls you have to cast it to an int.


"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar

The Second EuroCPian Event will be in Brussels on the 4th of September

Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!

My Blog


GeneralRe: enum question Pin
Werdna2-Jul-04 15:06
Werdna2-Jul-04 15:06 
GeneralRe: enum question Pin
Colin Angus Mackay2-Jul-04 15:19
Colin Angus Mackay2-Jul-04 15:19 
GeneralRe: enum question Pin
Mikke_x3-Jul-04 0:33
Mikke_x3-Jul-04 0:33 
GeneralRe: enum question Pin
Colin Angus Mackay3-Jul-04 12:08
Colin Angus Mackay3-Jul-04 12:08 
GeneralDatagrid Question Pin
C#Coder672-Jul-04 5:42
C#Coder672-Jul-04 5:42 
GeneralRe: Datagrid Question Pin
DougW482-Jul-04 6:57
DougW482-Jul-04 6:57 
GeneralMultiple instance of startup form Pin
Anonymous2-Jul-04 4:09
Anonymous2-Jul-04 4:09 
GeneralRe: Multiple instance of startup form Pin
Dave Kreskowiak2-Jul-04 4:57
mveDave Kreskowiak2-Jul-04 4:57 
GeneralRe: Multiple instance of startup form Pin
Anonymous2-Jul-04 5:32
Anonymous2-Jul-04 5:32 
GeneralRe: Multiple instance of startup form Pin
Dave Kreskowiak2-Jul-04 5:50
mveDave Kreskowiak2-Jul-04 5:50 
GeneralRe: Multiple instance of startup form Pin
Andreas X3-Jul-04 22:01
professionalAndreas X3-Jul-04 22:01 
GeneralOne port: multiple transfer Pin
Gimpy19832-Jul-04 4:08
Gimpy19832-Jul-04 4:08 
Generalinstall project paths Pin
mcgahanfl2-Jul-04 4:07
mcgahanfl2-Jul-04 4:07 
GeneralPlease see this Pin
saud_a_k2-Jul-04 1:31
saud_a_k2-Jul-04 1:31 
GeneralRe: Please see this Pin
Colin Angus Mackay2-Jul-04 2:10
Colin Angus Mackay2-Jul-04 2:10 
GeneralRe: Please see this Pin
saud_a_k2-Jul-04 2:48
saud_a_k2-Jul-04 2:48 
GeneralRe: Please see this Pin
Gary Thom2-Jul-04 2:29
Gary Thom2-Jul-04 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.