.NET API Documentation

Int32 Structure

Defined in: System
Assembly: System.Private.CoreLib
public struct Int32 : IComparable, IConvertible, IFormattable, IComparable<int>, IEquatable<int>

Represents a 32-bit signed integer type.

Fields

  • public const int MaxValue

    Returns the maximum value of a 32-bit signed integer, which is 2,147,483,647 (0x7FFFFFFF).

  • public const int MinValue

    Returns the minimum value of a 32-bit signed integer, which is -2,147,483,648 (0x80000000).

  • public const int Size

    The number of bytes used to store the value of a 32-bit integer.

  • public const int TicksPerDay

    This constant is not applicable to the Int32 structure and always returns 0.

Public Methods

  • public int CompareTo(int value)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

  • public int CompareTo(object obj)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

  • public bool Equals(int obj)

    Indicates whether the current instance is equal to another object of the same type.

  • public override bool Equals(object obj)

    Indicates whether this instance and a specified object are not equal.

  • public override int GetHashCode()

    Returns the hash code for the current instance.

  • public TypeCode GetTypeCode()

    Returns the TypeCode for value type. This returns the constant that is provided for the primitive type.

  • public override string ToString()

    Converts the numeric value of this instance to its equivalent string representation.

  • public string ToString(IFormatProvider provider)

    Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific formatting information.

  • public string ToString(string format)

    Converts the numeric value of this instance to its equivalent string representation using the specified format.

  • public string ToString(string format, IFormatProvider provider)

    Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific formatting information.

  • public static int Parse(string s)

    Converts the string representation of a number to its 32-bit signed integer equivalent.

  • public static int Parse(string s, IFormatProvider provider)

    Converts the string representation of a number to its 32-bit signed integer equivalent.

  • public static int Parse(string s, System.Globalization.NumberStyles style)

    Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

  • public static int Parse(string s, System.Globalization.NumberStyles style, IFormatProvider provider)

    Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

  • public static bool TryParse(string s, out int result)

    Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

  • public static bool TryParse(string s, System.Globalization.NumberStyles style, IFormatProvider provider, out int result)

    Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

Syntax Examples

Declaration

public struct Int32 : IComparable, IConvertible, IFormattable, IComparable<int>, IEquatable<int>

Basic Usage

int myNumber = 12345; Console.WriteLine(myNumber);

Arithmetic Operations

int a = 10; int b = 5; int sum = a + b; // 15 int difference = a - b; // 5 int product = a * b; // 50 int quotient = a / b; // 2

String Conversion

int value = 42; string strValue = value.ToString(); // "42" Console.WriteLine(strValue);

Parsing from String

string input = "987"; int parsedValue = int.Parse(input); Console.WriteLine(parsedValue);