Int32.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // System.Int32.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System.Globalization;
  10. namespace System {
  11. public struct Int32 : IComparable, IFormattable { //, IConvertible {
  12. public const int MaxValue = 0x7fffffff;
  13. public const int MinValue = -2147483648;
  14. public int value;
  15. public int CompareTo (object v)
  16. {
  17. if (!(v is System.Int32))
  18. throw new ArgumentException ("Value is not a System.Int32");
  19. return value - (int) v;
  20. }
  21. public override bool Equals (object o)
  22. {
  23. if (!(o is System.Int32))
  24. return false;
  25. return ((int) o) == value;
  26. }
  27. public override int GetHashCode ()
  28. {
  29. return value;
  30. }
  31. public static int Parse (string s)
  32. {
  33. return Parse (s, NumberStyles.Integer, null);
  34. }
  35. public static int Parse (string s, IFormatProvider fp)
  36. {
  37. return Parse (s, NumberStyles.Integer, fp);
  38. }
  39. public static int Parse (string s, NumberStyles style)
  40. {
  41. return Parse (s, style, null);
  42. }
  43. public static int Parse (string s, NumberStyles style, IFormatProvider fp)
  44. {
  45. // TODO: Implement me
  46. return 0;
  47. }
  48. public override string ToString ()
  49. {
  50. return ToString ("G", null);
  51. }
  52. public string ToString (IFormatProvider fp)
  53. {
  54. return ToString ("G", fp);
  55. }
  56. public string ToString (string format)
  57. {
  58. return ToString (format, null);
  59. }
  60. public string ToString (string format, IFormatProvider fp)
  61. {
  62. // TODO: use IFormatProvider.
  63. char[] ca = new char [20];
  64. int i = 19;
  65. int rem;
  66. if (value < 0) {
  67. ca [i] = '-';
  68. value = -value;
  69. i--;
  70. }
  71. do {
  72. rem = value % 10;
  73. value = value / 10;
  74. ca [i] = (char)('0' + rem);
  75. i--;
  76. } while (value > 0);
  77. return new String (ca, i + 1, 19 - i);
  78. }
  79. // =========== IConvertible Methods =========== //
  80. public TypeCode GetTypeCode ()
  81. {
  82. return TypeCode.Int32;
  83. }
  84. }
  85. }