mscorlib(4.0.0.0) API with additions
Int32.cs
4 using System.Security;
5 
6 namespace System
7 {
10  [ComVisible(true)]
11  [__DynamicallyInvokable]
13  {
14  internal int m_value;
15 
17  [__DynamicallyInvokable]
18  public const int MaxValue = 2147483647;
19 
21  [__DynamicallyInvokable]
22  public const int MinValue = -2147483648;
23 
30  public int CompareTo(object value)
31  {
32  if (value == null)
33  {
34  return 1;
35  }
36  if (value is int)
37  {
38  int num = (int)value;
39  if (this < num)
40  {
41  return -1;
42  }
43  if (this > num)
44  {
45  return 1;
46  }
47  return 0;
48  }
49  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeInt32"));
50  }
51 
55  [__DynamicallyInvokable]
56  public int CompareTo(int value)
57  {
58  if (this < value)
59  {
60  return -1;
61  }
62  if (this > value)
63  {
64  return 1;
65  }
66  return 0;
67  }
68 
73  [__DynamicallyInvokable]
74  public override bool Equals(object obj)
75  {
76  if (!(obj is int))
77  {
78  return false;
79  }
80  return this == (int)obj;
81  }
82 
87  [NonVersionable]
88  [__DynamicallyInvokable]
89  public bool Equals(int obj)
90  {
91  return this == obj;
92  }
93 
96  [__DynamicallyInvokable]
97  public override int GetHashCode()
98  {
99  return this;
100  }
101 
104  [SecuritySafeCritical]
105  [__DynamicallyInvokable]
106  public override string ToString()
107  {
108  return Number.FormatInt32(this, null, NumberFormatInfo.CurrentInfo);
109  }
110 
116  [SecuritySafeCritical]
117  [__DynamicallyInvokable]
118  public string ToString(string format)
119  {
120  return Number.FormatInt32(this, format, NumberFormatInfo.CurrentInfo);
121  }
122 
126  [SecuritySafeCritical]
127  [__DynamicallyInvokable]
128  public string ToString(IFormatProvider provider)
129  {
130  return Number.FormatInt32(this, null, NumberFormatInfo.GetInstance(provider));
131  }
132 
139  [SecuritySafeCritical]
140  [__DynamicallyInvokable]
141  public string ToString(string format, IFormatProvider provider)
142  {
143  return Number.FormatInt32(this, format, NumberFormatInfo.GetInstance(provider));
144  }
145 
155  [__DynamicallyInvokable]
156  public static int Parse(string s)
157  {
158  return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
159  }
160 
175  [__DynamicallyInvokable]
176  public static int Parse(string s, NumberStyles style)
177  {
178  NumberFormatInfo.ValidateParseStyleInteger(style);
179  return Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo);
180  }
181 
192  [__DynamicallyInvokable]
193  public static int Parse(string s, IFormatProvider provider)
194  {
195  return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
196  }
197 
213  [__DynamicallyInvokable]
214  public static int Parse(string s, NumberStyles style, IFormatProvider provider)
215  {
216  NumberFormatInfo.ValidateParseStyleInteger(style);
217  return Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider));
218  }
219 
225  [__DynamicallyInvokable]
226  public static bool TryParse(string s, out int result)
227  {
228  return Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
229  }
230 
241  [__DynamicallyInvokable]
242  public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out int result)
243  {
244  NumberFormatInfo.ValidateParseStyleInteger(style);
245  return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
246  }
247 
251  {
252  return TypeCode.Int32;
253  }
254 
259  [__DynamicallyInvokable]
261  {
262  return Convert.ToBoolean(this);
263  }
264 
268  [__DynamicallyInvokable]
270  {
271  return Convert.ToChar(this);
272  }
273 
277  [__DynamicallyInvokable]
279  {
280  return Convert.ToSByte(this);
281  }
282 
286  [__DynamicallyInvokable]
288  {
289  return Convert.ToByte(this);
290  }
291 
295  [__DynamicallyInvokable]
297  {
298  return Convert.ToInt16(this);
299  }
300 
304  [__DynamicallyInvokable]
306  {
307  return Convert.ToUInt16(this);
308  }
309 
313  [__DynamicallyInvokable]
315  {
316  return this;
317  }
318 
322  [__DynamicallyInvokable]
324  {
325  return Convert.ToUInt32(this);
326  }
327 
331  [__DynamicallyInvokable]
333  {
334  return Convert.ToInt64(this);
335  }
336 
340  [__DynamicallyInvokable]
342  {
343  return Convert.ToUInt64(this);
344  }
345 
349  [__DynamicallyInvokable]
351  {
352  return Convert.ToSingle(this);
353  }
354 
358  [__DynamicallyInvokable]
360  {
361  return Convert.ToDouble(this);
362  }
363 
367  [__DynamicallyInvokable]
369  {
370  return Convert.ToDecimal(this);
371  }
372 
377  [__DynamicallyInvokable]
379  {
380  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Int32", "DateTime"));
381  }
382 
387  [__DynamicallyInvokable]
388  object IConvertible.ToType(Type type, IFormatProvider provider)
389  {
390  return Convert.DefaultToType(this, type, provider);
391  }
392  }
393 }
float ToSingle(IFormatProvider provider)
Converts the value of this instance to an equivalent single-precision floating-point number using the...
Converts a base data type to another base data type.
Definition: Convert.cs:10
static long ToInt64(object value)
Converts the value of the specified object to a 64-bit signed integer.
Definition: Convert.cs:2506
static double ToDouble(object value)
Converts the value of the specified object to a double-precision floating-point number.
Definition: Convert.cs:3189
static int Parse(string s, IFormatProvider provider)
Converts the string representation of a number in a specified culture-specific format to its 32-bit s...
Definition: Int32.cs:193
string ToString(IFormatProvider provider)
Converts the numeric value of this instance to its equivalent string representation using the specifi...
Definition: Int32.cs:128
const int MaxValue
Represents the largest possible value of an T:System.Int32. This field is constant.
Definition: Int32.cs:18
TypeCode GetTypeCode()
Returns the T:System.TypeCode for value type T:System.Int32.
Definition: Int32.cs:250
override string ToString()
Converts the numeric value of this instance to its equivalent string representation.
Definition: Int32.cs:106
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
bool ToBoolean(IFormatProvider provider)
Converts the value of this instance to an equivalent Boolean value using the specified culture-specif...
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
static bool TryParse(string s, out int result)
Converts the string representation of a number to its 32-bit signed integer equivalent....
Definition: Int32.cs:226
static float ToSingle(object value)
Converts the value of the specified object to a single-precision floating-point number.
Definition: Convert.cs:2982
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
char ToChar(IFormatProvider provider)
Converts the value of this instance to an equivalent Unicode character using the specified culture-sp...
bool Equals(int obj)
Returns a value indicating whether this instance is equal to a specified T:System....
Definition: Int32.cs:89
Provides a mechanism for retrieving an object to control formatting.
static int Parse(string s)
Converts the string representation of a number to its 32-bit signed integer equivalent.
Definition: Int32.cs:156
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
static NumberFormatInfo CurrentInfo
Gets a read-only T:System.Globalization.NumberFormatInfo that formats values based on the current cul...
sbyte ToSByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture...
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
int CompareTo(object value)
Compares this instance to a specified object and returns an indication of their relative values.
Definition: Int32.cs:30
const int MinValue
Represents the smallest possible value of T:System.Int32. This field is constant.
Definition: Int32.cs:22
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Definition: NumberStyles.cs:10
Represents a 32-bit signed integer.To browse the .NET Framework source code for this type,...
Definition: Int32.cs:12
static char ToChar(object value)
Converts the value of the specified object to a Unicode character.
Definition: Convert.cs:670
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static bool ToBoolean(object value)
Converts the value of a specified object to an equivalent Boolean value.
Definition: Convert.cs:457
static int Parse(string s, NumberStyles style, IFormatProvider provider)
Converts the string representation of a number in a specified style and culture-specific format to it...
Definition: Int32.cs:214
decimal ToDecimal(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.Decimal number using the specified cult...
string ToString(string format)
Converts the numeric value of this instance to its equivalent string representation,...
Definition: Int32.cs:118
override bool Equals(object obj)
Returns a value indicating whether this instance is equal to a specified object.
Definition: Int32.cs:74
int ToInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit signed integer using the specified cultur...
static NumberFormatInfo GetInstance(IFormatProvider formatProvider)
Gets the T:System.Globalization.NumberFormatInfo associated with the specified T:System....
static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out int result)
Converts the string representation of a number in a specified style and culture-specific format to it...
Definition: Int32.cs:242
static ushort ToUInt16(object value)
Converts the value of the specified object to a 16-bit unsigned integer.
Definition: Convert.cs:1707
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
static sbyte ToSByte(object value)
Converts the value of the specified object to an 8-bit signed integer.
Definition: Convert.cs:909
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
ushort ToUInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified cult...
static uint ToUInt32(object value)
Converts the value of the specified object to a 32-bit unsigned integer.
Definition: Convert.cs:2235
string ToString(string format, IFormatProvider provider)
Converts the numeric value of this instance to its equivalent string representation using the specifi...
Definition: Int32.cs:141
short ToInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit signed integer using the specified cultur...
static decimal ToDecimal(object value)
Converts the value of the specified object to an equivalent decimal number.
Definition: Convert.cs:3394
long ToInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit signed integer using the specified cultur...
The exception that is thrown when one of the arguments provided to a method is not valid.
static int Parse(string s, NumberStyles style)
Converts the string representation of a number in a specified style to its 32-bit signed integer equi...
Definition: Int32.cs:176
override int GetHashCode()
Returns the hash code for this instance.
Definition: Int32.cs:97
static byte ToByte(object value)
Converts the value of the specified object to an 8-bit unsigned integer.
Definition: Convert.cs:1186
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
static short ToInt16(object value)
Converts the value of the specified object to a 16-bit signed integer.
Definition: Convert.cs:1452
Specifies that the class can be serialized.
ulong ToUInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified cult...
int CompareTo(int value)
Compares this instance to a specified 32-bit signed integer and returns an indication of their relati...
Definition: Int32.cs:56
static ulong ToUInt64(object value)
Converts the value of the specified object to a 64-bit unsigned integer.
Definition: Convert.cs:2727
byte ToByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified cultu...
Defines methods that convert the value of the implementing reference or value type to a common langua...
Definition: IConvertible.cs:9
Provides functionality to format the value of an object into a string representation.
Definition: IFormattable.cs:8
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
Provides culture-specific information for formatting and parsing numeric values.