Year End Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now
Difference between int, Int16, Int32 and Int64

Difference between int, Int16, Int32 and Int64

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

Best Free C# 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)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this