Int32 Struct
Namespace: System
Represents a 32-bit signed integer.
The Int32 value type represents whole numbers ranging from -2,147,483,648 through 2,147,483,647.
The Int32 type is the most commonly used integral type.
Inheritance
Object → Int32
Struct Members
-
Constant
Int32.Max
public const Int32 MaxRepresents the largest possible value for an Int32 type. -
Constant
Int32.Min
public const Int32 MinRepresents the smallest possible value for an Int32 type. -
Constant
Int32.MaxValue
public const Int32 MaxValueRepresents the largest possible value for an Int32 type. -
Constant
Int32.MinValue
public const Int32 MinValueRepresents the smallest possible value for an Int32 type. -
Constant
Int32.Epsilon
public const Int32 EpsilonThe difference between 1 and the next greater Int32 value that is adjacent to 1. -
Constant
Int32.One
public const Int32 OneRepresents the value of the Int32 type, which is 1. -
Constant
Int32.Zero
public const Int32 ZeroRepresents the value of the Int32 type, which is 0. -
Method
CompareTo
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, occurs at, or follows another object in sort order.Parameters:- value: An object to compare with this instance.
-
Method
Equals
public bool Equals(int obj)Indicates whether the current instance is equal to another object of the same type.Parameters:- obj: An object to compare with this instance.
-
Method
Parse
public static int Parse(string s)Converts the string representation of a number to its 32-bit signed integer equivalent.Parameters:- s: A string that contains a number to convert.
-
Method
ToString
public override string ToString()Converts the value of this instance to its equivalent string representation.
Example
Basic Usage of Int32
using System;
public class Example
{
public static void Main(string[] args)
{
int count = 100;
long total = 1000000000L;
Console.WriteLine($"The count is: {count}");
Console.WriteLine($"The total is: {total}");
// Perform arithmetic operations
int sum = count + 50;
Console.WriteLine($"Sum: {sum}");
// Comparison
if (count > 50)
{
Console.WriteLine("Count is greater than 50.");
}
// Parsing a string to int
string numberString = "123";
int parsedNumber = int.Parse(numberString);
Console.WriteLine($"Parsed number: {parsedNumber}");
// Using constants
Console.WriteLine($"Maximum Int32 value: {int.MaxValue}");
Console.WriteLine($"Minimum Int32 value: {int.MinValue}");
}
}
See Also