Enum
enum Color{
red, //0
blue, //1
orange, //3
}
Instead of hardcoding the numbers..use enum.
* symbolic name is used throughout the code, just change the number and recompile when ever necessary
* enumeration are strongly types..cant pass orange instead of wood.
* cant define an methods, properties or events.
* after compilation, each symbol is replaced by a constant field.
* enumerated type is just a structure that has a bunch of constant fields defined in it.
* After compilation, assembly that defined the enumerated type doesnt have to available at run time.
* fields can be byte, sbyte, short, ushort, uint,long, or ulong..int is default.
enum Color : byte{
Red,
Green,
Blue,
}
Console.WriteLine(Enum.GetUnderlyingType(typeof(Color)) ); //system.byte
Color co = Color.Green;
Console.WriteLine(co) //Green
Console.WriteLine(co.ToString()) //Green
Console.WriteLine(co.ToString("D")) 1
Console.WriteLine(Enum.Format(typeof(Color),(Byte)2,"G")); //Blue
Color[] cm = (Color[])Enum.GetValues(typeof(Color));
foreach(Color m in cm)
Console.WriteLine(m);
[Flags] attribute is applied so that a symbol matching each 1 bit islooked up and concatenated to a string; each symbol is separated by comma.
File Flags
* System.IO.File and System.IO.FileAttributes
*
* String fl = @"c:\YServer.txt";
System.IO.FileAttributes at=System.IO.File.GetAttributes(fl);
Console.WriteLine(at);
Friday, December 19, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment