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
I'll just post here since some of the other posts are slightly inaccurate in relation to C#.
Correct: int is an alias for System.Int32.
Wrong: float is not an alias for System.Float, but for System.Single
Basically, int is a reserved keyword in the C# programming language, and is an alias for the System.Int32 value type.
float and Float is not the same however, as the right system type for ''float'' is System.Single. There are some types like this that has reserved keywords that doesn't seem to match the type names directly.
In C# there is no difference between ''int'' and ''System.Int32'', or any of the other pairs or keywords/system types, except for when defining enums. With enums you can specify the storage size to use and in this case you can only use the reserved keyword, and not the system runtime type name.
Wether the value in the int will be stored on the stack, in memory, or as a referenced heap object depends on the context and how you use it.
This declaration in a method:
int i;
defines a variable i of type System.Int32, living in a register or on the stack, depending on optimizations. The same declaration in a type (struct or class) defines a member field. The same declaration in a method argument list defines a parameter, with the same storage options as for a local variable. (note that this paragraph is not valid if you start pulling iterator methods into the mix, these are different beasts altogether)
To get a heap object, you can use boxing:
object o = i;
this will create a boxed copy of the contents of i on the heap. In IL you can access methods on the heap object directly, but in C# you need to cast it back to an int, which will create another copy. Thus, the object on the heap cannot easily be changed in C# without creating a new boxed copy of a new int value. (Ugh, this paragraph doesn't read all that easily.)