![]() |
| | #1 |
| Registered User Join Date: May 2006
Posts: 1,579
| basic questions about enum I have 3 basic questions about Enum, from MSDN, http://msdn.microsoft.com/en-us/libr...32(VS.80).aspx 1. It is mentioned "A variable of type Days can be assigned any value in the range of the underlying type;" -- I think it is not correct to say any value in the range of the underlying type, like integer, but in the range from Sat to Fri. For example, you can not write Days d = 65535; 2. "and if additional elements have been added to the enum type, the test for default values can return true unexpectedly." I do not quite understand this scenario, could anyone show me some code please? 3. "You can notice these changes when using tools such as the Console class methods, the Expression Evaluator, and so forth. (See example 3).", I have tried example 3. But what are the rules for the changes when we add System.FlagsAttribute? The document only says there will be some changes, but not clearly states what will be the changes. Any ideas? thanks in advance, George |
| George2 is offline |
| | #2 | |||
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
Quote:
Code: enum e { a = 1, b = 8, c = 12 };
... // in a different module
e x;
switch(x)
{
case a:
...
case b:
...
default:
...
}
Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |||
| matsp is offline |
| | #3 | |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,125
| Quote:
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. | |
| Magos is offline |
| | #4 | ||
| Registered User Join Date: May 2006
Posts: 1,579
| Thanks Mats, 1. I have written a test program which shows whether or not using Flags attribute, the result value is the same, the presentation form is different when using Console.write method. Code: enum e1 { a,b,c,d};
[Flags]
enum e2 { a, b, c, d };
static void Main(string[] args)
{
e1 MyE1 = e1.a | e1.b;
e2 MyE2 = e2.a | e2.b;
// e1 == e2
return;
}
2. If yes, besides Console.write, any other presentation forms which will show the differences when using Flags attribute or not? Quote:
I do not agree, Magos! :-) It is ok to me. Could you show your complete test code please? Quote:
regards, George | ||
| George2 is offline |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Some basic C questions | WarDoGG | C Programming | 5 | 07-12-2008 10:40 AM |
| Stacks and enum questions | joenching | C++ Programming | 10 | 04-25-2005 06:39 PM |
| Switch case and enum help | SomeCrazyGuy | C++ Programming | 9 | 04-21-2005 08:53 PM |
| Please help, basic unsigned conversion questions | ninjacookies | C Programming | 3 | 04-20-2005 10:50 AM |
| enum | JerryL | C++ Programming | 5 | 02-25-2004 05:45 PM |