In both languages (Java and C#) int
is 4-byte signed integer.
Unlike Java, C# Provides both signed and unsigned integer values. As Java and C# are object object-oriented, some operations in these languages do not map directly onto instructions provided by the run time and so needs to be defined as part of an object of some type.
C# provides System.Int32
which is a value type using a part of memory that belongs to the reference type on the heap.
java provides java.lang.Integer
which is a reference type operating on int
. The methods in Integer
can't be compiled directly to run time instructions.So we box an int value to convert it into an instance of Integer and use the methods which expects instance of some type (like toString()
, parseInt()
, valueOf()
etc).
In C# variable int refers to System.Int32.Any
4-byte value in memory can be interpreted as a primitive int, that can be manipulated by instance of System.Int32.So int is an alias for System.Int32.When
using integer-related methods like int.Parse()
, int.ToString()
etc. Integer is compiled into the FCL System.Int32
struct calling the respective methods like Int32.Parse()
, Int32.ToString()
.