When to Use int vs Int32 or string vs String in C#

c++types

In C#, the keywords for built-in types are simply aliases for corresponding types in the System namespace.

Generally, it makes no difference whether you use a keyword (such as int) or an identifier (such as Int32) to refer to a built-in type. But there's an exception to everything, so my question in two parts is:

  1. When does C# require you to use, or not use, a keyword?
  2. When does using a keyword instead of an identifier change the meaning of the program?

Best Answer

C# doesn't require you to use one or the other as they are equivalent. It is a personal preference and coding convention. So use the one that seems more readable to you and your team. Just one advice: be consistent: do not use an alias in half of your codebase and the full type name in the second half.