What is the difference between int and System.Int32? Or string and System.String?
Posted: (EET/GMT+2)
Quite often, I see the question "What is the difference between int and System.Int32? Or string and System.String?" in C#/.NET related newsgroups and forums popping up. There's also an answer to this question in the MSDN C# FAQ, but since not many are aware of this FAQ, I give my version of the answer here.
So, what is the difference between, say, int and Int32 in C#? The answer is that there's no difference at all. As noted in the C# Language Specification 1.2 (this also applies to C# 2.0 and 3.0), section 4.1.4, "Simple Types":
C# provides a set of predefined struct types called the simple types. The simple types are identified through reserved words, but these reserved words are simply aliases for predefined struct types in the System namespace, as described in the table below.And, a table from the C# Reference follows:
| C# Type | .NET Framework Type |
| bool | System.Boolean |
| byte | System.Byte |
| sbyte | System.SByte |
| char | System.Char |
| decimal | System.Decimal |
| double | System.Double |
| float | System.Single |
| int | System.Int32 |
| uint | System.UInt32 |
| long | System.Int64 |
| ulong | System.UInt64 |
| object | System.Object |
| short | System.Int16 |
| ushort | System.UInt16 |
| string | System.String |
That said, it doesn't matter whether you choose to use System.String or string. Both work equally well, lead to fast code, and so on. The difference is only cosmetic.