Home »
C#.Net
int keyword in C#
C# int keyword: Here, we are going to learn about the int keyword in C#, what is int keyword, how to use it in C#?
Submitted by IncludeHelp, on March 07, 2019
C# int keyword
In C#, int is a keyword which is used to declare a variable that can store an integral type of value (signed integer) the range of -2,147,483,648 to 2,147,483,647. int keyword is an alias of System.Int32.
It occupies 4 bytes (32 bits) space in the memory.
Syntax:
int variable_name = value;
C# code to demonstrate example of int keyword
Here, we are declaring an int variable num, initializing it with the value 12345 and printing its value, type, and size of an int type variable.
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//variable declaration
int num = 12345;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size
Console.WriteLine("Size of a int variable: " + sizeof(int));
//printing minimum & maximum value of int
Console.WriteLine("Min value of int: " + int.MinValue);
Console.WriteLine("Max value of int: " + int.MaxValue);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
num: 12345
Type of num: System.Int32
Size of a int variable: 4
Min value of int: -2147483648
Max value of int: 2147483647