C# | Int32 Struct
In C#, Int32 Struct represents 32-bit signed integer(also termed as int data type) starting from range -2,147,483,648 to +2,147,483,647. It also provides different types of method to perform various operations. You can perform the mathematical operation like addition, subtraction, multiplication, etc. on Int32 type. It supports bitwise operations like AND, OR, XOR, etc. It provides full support for standard and custom numeric format strings. You can call the methods of Convert and Math class to perform operations on Int32 value. Int32 struct inherits the ValueType class which inherits the Object class.
Fields
Fields | Description |
---|---|
MaxValue | This field is used to represent the largest possible value of an Int32. This field is constant. |
MinValue | This field is used to represent the smallest possible value of Int32. This field is constant. |
Example:
// C# program to illustrate the // MaxValue and MinValue field using System; class GFG { // Main method static public void Main() { Int32 var1 = 34; Int32 var2 = 30; Int32 var3 = 59; // Get the Maximum and Minimum value // of Int32 type Using MaxValue and // MinValue field Console.WriteLine( "Value 1: {0}" , var1); Console.WriteLine( "Value 2: {0}" , var2); Console.WriteLine( "Value 3: {0}" , var3); Console.WriteLine( "Maximum Value: {0}" , Int32.MaxValue); Console.WriteLine( "Minimum Value: {0}" , Int32.MinValue); } } |
Output:
Value 1: 34 Value 2: 30 Value 3: 59 Maximum Value: 2147483647 Minimum Value: -2147483648
Methods
Method | Description |
---|---|
CompareTo() | This method is used to compare this instance to a specified object or Int32 and returns an indication of their relative values. |
Equals() | This method is used to return a value indicating whether this instance is equal to a specified object or Int32. |
GetHashCode() | This method is used to return the hash code for this instance. |
GetTypeCode() | This method is used to return the TypeCode for value type Int32. |
Parse() | This method is used to convert the string representation of a number to its 32-bit signed integer equivalent. |
ToString() | This method is used to convert the numeric value of this instance to its equivalent string representation. |
TryParse() | This method is used to convert the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the operation succeeded. |
Example 1:
// C# program to demonstrate the // Int32.Equals(Object) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring and initializing value1 int value1 = 70; // Declaring and initializing value2 object value2 = 89; // using Equals(object) method bool status = value1.Equals(value2); // checking the status if (status) Console.WriteLine( "{0} is equal to {1}" , value1, value2); else Console.WriteLine( "{0} is not equal to {1}" , value1, value2); } } |
Output:
70 is not equal to 89
Example 2:
// C# program to illustrate the // GetTypeCode() method using System; class GFG { // Main method static public void Main() { Int32 var1 = 100; Int32 var2 = 403; Int32 var3 = 503; // Get the type code of // all the variables // Using GetTypeCode() method Console.WriteLine( "Get the type code of var1: {0}" , var1.GetTypeCode()); Console.WriteLine( "Get the type code of var2: {0}" , var2.GetTypeCode()); Console.WriteLine( "Get the type code of var3: {0}" , var3.GetTypeCode()); } } |
Output:
Get the type code of var1: Int32 Get the type code of var2: Int32 Get the type code of var3: Int32
Reference:
Please Login to comment...