3

I've seen an increasing trend of people submitting code to SO that includes the use of .NET Framework data types.

I understand that the .NET Framework has its own data types (like Int16, Int32, Boolean, etc) that map to the appropriate data type in the language you are using (like C#). But why use that over the language-specific data type? Is there a specific reason to do this or certain case where using a .NET Framework data type would be more advantageous than a language-specific data type?

2
  • 4
    When you're sad, use int, because it is dark blue. When you are light and happy, use Int32, because it is light blue!
    – svidgen
    May 27 '16 at 20:33
  • 2
    ... when you are ANGRY, use IntThatDoesNotExist, because it will be black like your soul and underlined in angry red squiggles.
    – svidgen
    May 27 '16 at 20:34
10

These are not two distinct, different types - System.String and string are not equivalent types, they are simply two aliases to the same type.

The choice of using one or the other is thus entirely stylistic. One project or programmer might say "int is the native C# term. It's short and clear and intuitive, and thus I will always use it". Another might say "Int32 is universal and unambiguous. It means the same whether I'm using C# or VB or F# and anyone reading it knows what it means without having to know the specific language in question".

Both are valid. Both might be more useful in different contexts (a pure C# project vs. a mixed-language project), but they map to the same IL, the same machine code, the same runtime in the end.

2
  • So in reality then, the "language-specific" type (for lack of a better term) is just an alias; the ".NET Framework type" is the type right? May 27 '16 at 17:55
  • @Sylverac Yes. As long as C# is running on top of the .NET framework, of course. May 27 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.