- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Int32.MaxValue Field in C# with Examples
The Int32.MaxValue field in C# is used to represent the largest possible value of an Int32.
Syntax
Following is the syntax −
public const int MaxValue = 2147483647;
Example
Let us now see an example to implement the Int32.MaxValue field −
using System;
public class Demo {
public static void Main(){
int val1 = 23;
int val2 = 23;
Console.WriteLine("Value1 = "+val1);
Console.WriteLine("Value2 = "+val2);
Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
Console.WriteLine("TypeCode for val1 = "+type1);
Console.WriteLine("TypeCode for val2 = "+type2);
Console.WriteLine("Maximum Value = "+ Int32.MaxValue);
}
}Output
This will produce the following output −
Value1 = 23 Value2 = 23 HashCode for value1 = 23 HashCode for value2 = 23 Are they equal? = True TypeCode for val1 = Int32 TypeCode for val2 = Int32 Maximum Value = 2147483647
Example
Let us now see another example to implement the Int32.MaxValue field −
using System;
public class Demo {
public static void Main(){
long[]val = {8998, -899898778, 8787867687878, -20};
int res;
foreach(long a in val){
if(a >= Int32.MinValue && a <= Int32.MaxValue){
res = Convert.ToInt32(a);
Console.WriteLine("Converted: "+res);
}
else{
Console.WriteLine("Not Possible");
}
}
}
}Output
This will produce the following output −
Converted: 8998 Converted: -899898778 Not Possible Converted: -20
- Related Articles
- UInt16.MaxValue Field in C# with Examples
- UInt32.MaxValue Field in C# with Examples
- Int16.MaxValue Field in C# with Examples
- UInt64.MaxValue Field in C# with Examples
- Int64.MaxValue Field in C# with Examples
- Int32.MinValue Field in C# with Examples
- Array.BinarySearch(Array, Int32, Int32, Object) Method with examples in C#
- Int32.GetTypeCode Method in C# with Examples
- Int32.CompareTo Method in C# with Examples
- Int32. Equals Method in C# with Examples
- Int32.GetHashCode Method in C# with Examples
- Char.GetUnicodeCategory(String, Int32) Method with Examples in C#
- UInt32.MinValue Field in C# with Examples
- Int16.MinValue Field in C# with Examples
- UInt16.MinValue Field in C# with Examples
Advertisements
