public struct Int32 : IComparable, IFormattable, IComparable<Int32>, IEquatable<Int32>
Object
ValueType
Int32This type implements IComparable, IFormattable, System.IComparable<System.Int32>, and System.IEquatable<System.Int32>.
mscorlib
BCL
Represents a 32-bit signed integer.
The Int32 data type represents integer values ranging from negative 2,147,483,648 to positive 2,147,483,647; that is, hexadecimal 0X80000000 to 0X7FFFFFFF.
System Namespace
Int32 Methods
Int32.CompareTo(int) Method
Int32.CompareTo(System.Object) Method
Int32.Equals(int) Method
Int32.Equals(System.Object) Method
Int32.GetHashCode Method
Int32.Parse(System.String) Method
Int32.Parse(System.String, System.Globalization.NumberStyles) Method
Int32.Parse(System.String, System.IFormatProvider) Method
Int32.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
Int32.ToString(System.IFormatProvider) Method
Int32.ToString(System.String, System.IFormatProvider) Method
Int32.ToString() Method
Int32.ToString(System.String) Method
Int32 Fields
public int CompareTo(int value);
Returns the sort order of the current instance compared to the specified Int32.
- value
- The Int32 to compare to the current instance.
The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
Return Value Description A negative number Current instance < value. Zero Current instance == value. A positive number Current instance > value.
[Note: This method is implemented to support the System.IComparable<Int32> interface.]
System.Int32 Structure, System Namespace
public int CompareTo(object value);
Returns the sort order of the current instance compared to the specified Object.
- value
- The Object to compare to the current instance.
The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
Return Value Description A negative number Current instance < value. Zero Current instance == value. A positive number Current instance > value, or value is a null reference.
Exception Type Condition ArgumentException value is not a Int32 and is not a null reference.
[Note: This method is implemented to support the IComparable interface.]
System.Int32 Structure, System Namespace
public override bool Equals(int obj);
Determines whether the current instance and the specified Int32 represent the same value.
- obj
- The Int32 to compare to the current instance.
true
if obj represents the same and value as the current instance; otherwise,false
.
[Note: This method is implemented to support the System.IEquatable<Int32> interface.]
System.Int32 Structure, System Namespace
public override bool Equals(object obj);
Determines whether the current instance and the specified Object represent the same type and value.
- obj
- The Object to compare to the current instance.
true
if obj represents the same type and value as the current instance. If obj is a null reference or is not an instance of Int32, returnsfalse
.
[Note: This method overrides System.Object.Equals(System.Object).]
System.Int32 Structure, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.Int32 Structure, System Namespace
public static int Parse(string s);
Returns the specified String converted to a Int32 value.
- s
- A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
The Int32 value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Int32.MaxValue or less than System.Int32.MinValue.
This version of System.Int32.Parse(System.String) is equivalent to System.Int32.Parse(System.String)(s, System.Globalization.NumberStyles.Integer,null
).The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo.]
This example demonstrates parsing a string to a Int32.
using System; public class Int32ParseClass { public static void Main() { string str = " 100 "; Console.WriteLine("String: \"{0}\" <Int32> {1}",str,Int32.Parse(str)); } }The output is
String: " 100 " <Int32> 100
System.Int32 Structure, System Namespace
public static int Parse(string s, NumberStyles style);
Returns the specified String converted to a Int32 value.
- s
- A String containing the value to convert. The string is interpreted using the style specified by style.
- style
- Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Integer style.
The Int32 value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Int32.MaxValue or less than System.Int32.MinValue.
This version of System.Int32.Parse(System.String) is equivalent to System.Int32.Parse(System.String) (s, style,null
).The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo.]
System.Int32 Structure, System Namespace
public static int Parse(string s, IFormatProvider provider);
Returns the specified String converted to a Int32 value.
- s
- A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
- provider
- A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.
The Int32 value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Int32.MaxValue or less than System.Int32.MinValue.
This version of System.Int32.Parse(System.String) is equivalent to System.Int32.Parse(System.String)(s, System.Globalization.NumberStyles.Integer, provider).The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is
null
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.
System.Int32 Structure, System Namespace
public static int Parse(string s, NumberStyles style, IFormatProvider provider);
Returns the specified String converted to a Int32 value.
- s
- A String containing the value to convert. The string is interpreted using the style specified by style.
- style
- Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Integer style.
- provider
- A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.
The Int32 value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Int32.MaxValue or less than System.Int32.MinValue.
The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider isnull
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.
System.Int32 Structure, System Namespace
public string ToString(IFormatProvider provider);
Returns a String representation of the value of the current instance.
- provider
- A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.
A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.
This version of System.Int32.ToString is equivalent to System.Int32.ToString("G", provider).If provider is
null
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.
System.Int32 Structure, System Namespace
public string ToString(string format, IFormatProvider provider);
Returns a String representation of the value of the current instance.
- format
- A String containing a character that specifies the format of the returned string.
- provider
- A IFormatProvider that supplies a NumberFormatInfo instance containing culture-specific formatting information.
A String representation of the current instance formatted as specified by format. The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.
Exception Type Condition FormatException format is invalid.
If provider isnull
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.If format is a null reference, the general format specifier "G" is used.
[Note: For a detailed description of formatting, see the IFormattable interface.
This method is implemented to support the IFormattable interface.
]
The following table lists the characters that are valid for the Int32 type.
Item Description "C", "c" Currency format. "D", "d" Decimal format. "E", "e" Exponential notation format. "F", "f" Fixed-point format. "G", "g" General format. "N", "n" Number format. "P", "p" Percent format. "X", "x" Hexadecimal format.
System.Int32 Structure, System Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
A String representation of the current instance formatted using the general format specifier ("G"). The string takes into account the current system culture.
This version of System.Int32.ToString is equivalent to System.Int32.ToString (null
,null
).[Note: This method overrides System.Object.ToString.]
System.Int32 Structure, System Namespace
public string ToString(string format);
Returns a String representation of the value of the current instance.
- format
- A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Int32.ToString(String, IFormatProvider).]
A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.
Exception Type Condition FormatException format is invalid.
This method is equivalent to System.Int32.ToString(format,null
).If format is a null reference, the general format specifier "G" is used.
This example demonstrates converting a Int32 to a string.
using System; public class Int32ToStringExample { public static void Main() { Int32 i = 32; Console.WriteLine(i); String[] formats = {"c", "d", "e", "f", "g", "n", "p", "x" }; foreach(String str in formats) Console.WriteLine("{0}: {1}", str, i.ToString(str)); } }The output is
32
c: $32.00
d: 32
e: 3.200000e+001
f: 32.00
g: 32
n: 32.00
p: 3,200.00 %
x: 20
System.Int32 Structure, System Namespace
public const int MaxValue = 2147483647;
Contains the maximum value for the Int32 type.
The value of this constant is 2,147,483,647 (hexadecimal 0X7FFFFFFF).
System.Int32 Structure, System Namespace
public const int MinValue = -2147483648;
Contains the minimum value for the Int32 type.
The value of this constant is -2,147,483,648 (hexadecimal 0X80000000).
System.Int32 Structure, System Namespace