public struct Int32: IComparable, IFormattable { //Constructors public Int32 (int value); //Fields public readonly const int MinValue = -2147483648; public readonly const int MaxValue = 2147483647; //Properties public int Value { virtual get; } //Methods public static string ToString(int i); public override string ToString(); public static int Parse(string s, NumberStyle style, NumberFormatInfo info); public static int Parse(string s, NumberStyle style); public static int Parse(string s); public override int GetHashCode(); public static int FromString(string s); public virtual string Format(string format, IServiceObjectProvider sop); public static string Format(int value, string format, NumberFormatInfo info); public static string Format(int value, string format); public override bool Equals(object obj); public virtual int CompareTo(object object); public static object Box(int value); }
Always define enumerated values using an enum if they are used in a parameter or property. This allows the tool to know the possible values for a property or parameter.
public enum SpecialFolder { ApplicationData, UserData , Cookies, DesktopDirectory, Favorites, History, InternetCache, Programs, Recent, Sendto, StartMenu, Startup, Templates } Type.CreateInstance (IBinder binder, BindingEnum bindAttributes, Variant [] args)
[Flags(true)] public enum Bindings { IgnoreCase = 0x01; NonPublic = 0x02; Static = 0x04; InvokeMethod = 0x0100; CreateInstance = 0x0200; GetField = 0x0400; SetField = 0x0800; GetProperty = 0x1000; SetProperty = 0x2000; DefaultBinding = 0x010000; DefaultChangeType = 0x020000; Default = DefaultBinding | DefaultChangeType; ExactBinding = 0x040000; ExactChangeType = 0x080000; BinderBinding = 0x100000; BinderChangeType = 0x200000;
public void SetColor (Color color) { if (!EnumInfo.IsValid (typeof(color), color) throw new ArgumentOutOfRangeException(); }
unless:
The enum represents flags and there are many flags (>32) or the enum may grow to many flags in the future.
The type needs to be different than int for backward compatibility.