Blog powered by TypePad

« What's So Bad About Smalltalk? | Main | getopt in Java, TDD-style »

January 23, 2004

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8342a671a53ef00d834c7f49953ef

Listed below are links to weblogs that reference More C# 'enum' Wackiness:

Comments

Mike Withrow

Besides the first glance I found your site to be very useful although is there a way we can get just a little more green?

Andrew

It seems the enumerator list must begin with a character. It seems all the named constants below are in error except the last one. In my particular circumstance this is confining.

public enum SamplingFrequency
{
8000, //error, invalid token
9000 = 1,
10000 = 10000,
15caps,
char55 // Named constants must begin with a char.
};

Andrew

I think I found my answer. C# identifers are based on Unicode characters and may only begin with a character, underscore, or '@'.

Jesse

what's the big deal? ... the quote you cited from Eric Gunnerson answered all your questions ... did you do that on purpose? don't use an enum if you want something water tight in the same way that you don't use an int if you want a string ...

Michael

i seem to agree with the rationale for allowing zero to implicitly denote a no-value enum, until i saw this article:

http://plus.kaist.ac.kr/~shoh/postgresql/Npgsql/apidocs/Npgsql.NpgsqlParameterCollection.Add_overload_3.html

can C# team find a more elegant solution for enum that are zero value?


i'm looking forward for them to clean up this enum's zero wackiness


i think implicitly casting zero to enum type is not a good decision

Ben Kloosterman

One of the main things enum Flags are used for is C++ interop ..

If you want high performance but low abstraction use enums
1) Enums also have issues with serialization eg it allows a client to send a value of say 12 that does not match a value on a service - however it is valid for the enum . It gets send and somewhere in your service it will crash or you will get an illegal value in a db.

2) You can also use arithmatic on enums eg Red+1 ... = Yellow .. Certainly not intended by most devs.

If you want better programming , make your own enum ie use a class and statics to represent the values = type safe.

If you want performance / C++ interop use enums.

Regards,

Ben

wpdnra ngefo

duyia cwkt zgvbkwxim zqsmfylpt uievozwnc yszeg bgwu

Web Designing Karachi

Good post..here’s some additional related info.

propecia

i like this part of the blog:" if ( !Enum.IsDefined( typeof( CardSuit ), suit ) )
throw new ArgumentOutOfRangeException(
"suit", suit, "invalid suit value" );" is very good

Puma Clyde

Advantageous post, I favor to create tips since it allows bloggers for getting even more engaged and towards the possibility to surely know from each and every other.

neocheelato

Greetings I'm brand new here and just wanted to say hello. Send me a PM if you wanna chat sometime i'm open for conversations.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment