Casting an enum, skips one for no reason?
- From: "PokerMan" <nospam@xxxxxxxxxxxxxx>
- Date: Fri, 2 Feb 2007 18:24:30 -0000
Hi guys,
Maybe someone can explain thisi have this enum:
public enum LimitType : int
{
BottomLimit,
TopLimit,
Limit
}
In another class i read values from my db and cast them to the enum, where
my db id is 1, it will match the enum that is first and so on:
pt = (myClass.LimitType )int.Parse(limitType);
Here is the weird bit, if limitType is a 1, pt becomes BottomLimit. Correct.
if it is a 2 it becomes TopLimit. Correct.
if it is a 3, it becomes the integer 3. Wrong!?
I thought maybe limit is some kind of keyword to the compiler, so i changed
the enum to this:
public enum LimitType : int
{
BottomLimit,
TopLimit,
Limit,
test
}
Ran it again and in debug this happened:
if limitType is a 1, pt becomes BottomLimit. Correct.
if it is a 2 it becomes TopLimit. Correct.
if it is a 3, it becomes test !? Wrong.
Can anyone explain why it seems to be choosing to skip Limit as though it
isn't there? In debug when i check the enum at runtime it does have Limit as
one of the enums and it is in that order. Look forward to the replies.
.
- Follow-Ups:
- Re: Casting an enum, skips one for no reason?
- From: Lebesgue
- Re: Casting an enum, skips one for no reason?
- From: PokerMan
- Re: Casting an enum, skips one for no reason?
- From: Bruce Wood
- Re: Casting an enum, skips one for no reason?
- Prev by Date: Re: Problem with C# not calling MC++ destrcutor
- Next by Date: Re: Problem with C# not calling MC++ destrcutor
- Previous by thread: Save bmp/jpg/png...to icon (16x16) - Problem..
- Next by thread: Re: Casting an enum, skips one for no reason?
- Index(es):
Relevant Pages
|
Loading