I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an i
This has already been answered for Java, here's the C# answer:
"Integer" is not a valid type name in C# and "int" is just an alias for System.Int32. Also, unlike in Java (or C++) there aren't any special primitive types in C#, every instance of a type in C# (including int) is an object. Here's some demonstrative code:
void DoStuff()
{
System.Console.WriteLine( SomeMethod((int)5) );
System.Console.WriteLine( GetTypeName<int>() );
}
string SomeMethod(object someParameter)
{
return string.Format("Some text {0}", someParameter.ToString());
}
string GetTypeName<T>()
{
return (typeof (T)).FullName;
}
In C#, int is just an alias for System.Int32
, string for System.String
, double for System.Double
etc...
Personally I prefer int, string, double, etc. because they don't require a using System;
statement :) A silly reason, I know...
In Java, the int
type is a primitive data type, where as the Integer
type is an object.
In C#, the int
type is also a data type same as System.Int32
. An integer
(just like any other value types) can be boxed ("wrapped") into an object.
int
is predefined in library function c# but in java we can create object of Integer
In java as per my knowledge if you learner then, when you write int a; then in java generic it will compile code like Integer a = new Integer()
.
So,as per generics Integer
is not used but int
is used.
so there is so such difference there.
int is a primitive data type. Integer is a wrapper class. It can store int data as objects.