5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
15 public struct UInt16 : IComparable, IFormattable { //, IConvertible {
16 private static Type Type = typeof (ushort);
18 public const ushort MaxValue = 0xffff;
19 public const ushort MinValue = 0;
23 public int CompareTo (object v)
25 if (!(v is System.UInt16))
26 throw new ArgumentException ("Value is not a System.UInt16");
28 return value - ((ushort) v);
31 public override bool Equals (object o)
33 if (!(o is System.UInt16))
36 return ((ushort) o) == value;
39 public override int GetHashCode ()
44 public static ushort Parse (string s)
46 return Parse (s, NumberStyles.Integer, null);
49 public static ushort Parse (string s, IFormatProvider fp)
51 return Parse (s, NumberStyles.Integer, fp);
54 public static ushort Parse (string s, NumberStyles style)
56 return Parse (s, style, null);
59 public static ushort Parse (string s, NumberStyles style, IFormatProvider fp)
65 public override string ToString ()
67 return ToString ("G", null);
70 public string ToString (IFormatProvider fp)
72 return ToString ("G", fp);
75 public string ToString (string format)
77 return ToString (format, null);
80 public string ToString (string format, IFormatProvider fp)
85 fmt = (format == null) ? "G" : format;
88 nfi = NumberFormatInfo.CurrentInfo;
90 nfi = (NumberFormatInfo) fp.GetFormat (Type);
93 nfi = NumberFormatInfo.CurrentInfo;
96 return IntegerFormatter.NumberToString (fmt, nfi, value);
99 // =========== IConvertible Methods =========== //
101 public TypeCode GetTypeCode ()
103 return TypeCode.UInt16;