Reputation:
Why and when should we use int
, int16
, int32
, int64
, double
, string
instead of Int
, Int16
, Int32
, Int64
, Double
, String
respectively? I have ready many articles about this but still not getting a proper solution.
Upvotes: 2
Views: 266
Reputation: 1500065
It doesn't matter at all in implementation. I personally prefer using the aliases, and from what I've seen of other code that's the more common choice. There are some who suggest using the BCL names (Int32
etc) everywhere though - including Jeffrey Richter, author of CLR via C# (where he gives that advice).
However, when you're naming methods and types, you should use the BCL name rather than the C#-specific name. That way your code is equally idiomatic to people using your code from other languages. This is the convention adopted within the BCL itself. For example, we have Convert.ToInt32
and Convert.ToSingle
instead of Convert.ToInt
and Convert.ToFloat
.
While it doesn't matter in theory if those are internal or private members, I'd suggest getting in the habit of giving your members the names you'd want to expose publicly - it means you can be consistent there regardless of access, and you're less likely to accidentally let one slip through.
Upvotes: 2
Reputation: 457
It truly does not matter, just be consistent. I personally use the original, lowercase names.
Upvotes: 1
Reputation: 2051
This is purely a matter of preference/tradition.
C# language specification states:
Each of the predefined types is shorthand for a system-provided type. For example, the keyword int refers to the struct System.Int32. As a matter of style, use of the keyword is favoured over use of the complete system type name.
Upvotes: 5