Difference between int, Int16, Int32 and Int64

Difference between int, Int16, Int32 and Int64

23 May 2024
Intermediate
154K Views
8 min read
Learn with an interactive course and practical hands-on labs

Free C# Foundation Course: Learn C# In 21 Days

The Int DataType: An Overview

In the learning phase, developers are not very aware of the difference between primitive, FCL (framework class library), reference, and value types. This causes bugs and performance issues in the code. there are different behaviors of integer types. In this C# Tutorial, we will explore more about C Sharp int datatypewhich will include C# int Int16 Int32 Int64, int vs Int16 vs Int32 vs Int64.

int

  1. It is a primitive data type defined in C#.

  2. It is mapped to Int32 of FCL type.

  3. It is a value type and represents a System.Int32 struct.

  4. It is signed and takes 32 bits.

  5. It has a minimum of -2147483648 and a maximum of +2147483647 capacity.

Example

Let's elaborate more about int datatype in C# Compiler

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace HelloWorld
{
	public class Program
	{
		public static void Main(string[] args)
		{
			{
	// Integer value
	int a = 9;
	Console.WriteLine("Integer value="+ a);
}
		}
	}
}

Output

   Integer value=9

Read More - C# Programming Interview Questions

Int16

  1. It is a FCL type.

  2. In C#, the short is mapped to Int16.

  3. It is a value type and represents the System.Int16 struct.

  4. It is signed and takes 16 bits.

  5. It has a minimum -32768 and maximum +32767 capacity.

Example:

 using System; 
using System.Text; 

public class Scholarhat
 { 
static void Main(string[] args) 
{ 

	Console.WriteLine("Int16 MinValue: "+ Int16.MinValue); 
	Console.WriteLine("Int16 MaxValue: "+ Int16.MaxValue); 
	Console.WriteLine(); 

	Int16[] arr1 = {-5, 1, 4, 4, 8}; 

	foreach (Int16 i in arr1) 
	{ 
	Console.WriteLine(i); 
	} 
} 
} 

Output

 Int16 MinValue: -32768
Int16 MaxValue: 32767
-5
1
4
4
8

Int32

  1. It is an FCL type.

  2. In C#, int is mapped to Int32.

  3. It is a value type and represents the System.Int32 struct.

  4. It is signed and takes 32 bits.

  5. It has a minimum -2147483648 and a maximum +2147483647 capacity.

Example:

 using System; 
using System.Text; 

public
class Scholarhat { 

static void Main(string[] args) { 

	Console.WriteLine("Int32 MinValue: "+ Int32.MinValue); 
	Console.WriteLine("Int32 MaxValue: "	+ Int32.MaxValue); 
	Console.WriteLine(); 

	Int32[] arr1 = {-4, 0, 3, 2, 9}; 

	foreach (Int32 i in arr1) 
	{ 
	Console.WriteLine(i); 
	} 
} 
}

 

Output

 
int32 MinValue: -2147483648
Int32 MaxValue: 2147483647

-4
0
3
2
9
 

Int64

  1. It is a FCL type.

  2. In C#, the long is mapped to Int64.

  3. It is a value type and represents the System.Int64 struct.

  4. It is signed and takes 64 bits.

  5. It has a minimum of 9,223,372,036,854,775,808 and a maximum of 9,223,372,036,854,775,807 capacity.

Example:

 
using System; 
using System.Text; 

public class Scholarhat { 

static void Main(string[] args) { 

	Console.WriteLine("Int64 MinValue: "+ Int64.MinValue); 
	Console.WriteLine("Int64 MaxValue: "	+ Int64.MaxValue); 
	Console.WriteLine(); 

	Int64[] arr1 = {-4, 0, 3, 5, 9}; 

	foreach (Int64 i in arr1) 
	{ 
	Console.WriteLine(i); 
	} 
} 
}


 

Output

 Int64 MinValue: -9223372036854775808
Int64 MaxValue: 9223372036854775807

-4
0
3
5
9 

Note

  1. A number of developers think that int represents a 32-bit integer when the application is running on a 32-bit OS and it represents a 64-bit integer when the application is running on a 64-bit OS. This is absolutely wrong.

  2. In C# int is a primitive data type and it is always mapped to System.Int32 whether the OS is 32-bit or 64-bit.

Difference between int, Int16, Int32 and Int64:

Conclusion:

I hope you will enjoy the tips while programming with C#. I would like to have feedback from my blog readers. Your valuable feedback, questions, or comments about this article are always welcome. Also, Consider our C# Programming Course for a better understanding of all C# concepts.

FAQs

Int16 can only store values up to 32,767 , Int32 can store values up to 2,147,483,647 and Int64 can store values up to 9,223,372,036,854,775,807

In theory the int16 is going to be slower than the int32 as it will be cast up to that before the comparison is made

 A 16-bit integer means there are 2^16 possible values - generally represented as between 0 and 65,535. 32-bit values range from 0 to 2^32 - 1, or just over 4.29 billion values.

Take our Csharp skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET FREE CHALLENGE

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 9th time in a row (2016-2024). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this