Accepted style for long vs Int64 in C#? [closed]

I know they are the same variable type, but is there an accepted standard 'style' for whether to use long or Int64?

I would like to use the most common one.


All documentation from Microsoft and 99.999% (or so) of the code you'll find online will use long. See for instance the numeric datatype definition in the C# reference: http://msdn.microsoft.com/en-us/library/exx3b86w.aspx

In the end, this is the same issue with using string or String. In general, lowercase names are used for value datatypes like numbers or characters, and uppercase names are used for classes. In C# Int64 is the complex datatype (a structure with fields, properties and methods, see the doc here) for the long value datatype (see the doc here). In general, people don't use the class Int64 for other than invoking methods from that class, such as Int64.Parse. So you will usually find something like this:

long variable = 9.5f;
string text = "8.4";
long anotherVariable = Int64.Parse(text);

You will get so many different opinions for a question like this since they're the exact same thing. So it's up to you. Microsoft pretty much always uses long, int and short in their documentation and examples. It's simply an Alias in VB.NET and C#. So I guess it's better usage to use them that way.

  • long instead of Int64
  • int instead of Int32
  • short instead of Int16

C# uses these keywords like long, int string, as aliases for .NET-types.

  • int = System.Int32
  • long = System.Int64
  • string = System.String

The first argument to use these keywords is that it comes with the language, so use it when writing the language.

A second argument of using these keywords is that you do not have to put using System; above your codefile.

Another benefit could be that someone could create a new type called Int64 and put it somewhere in your namespace (I know... it would be crazy). If your older code uses the type Int64, your older code could stop functioning. If your older code was using long (an alias for System.Int64) than it would still work fine.


You should use long, int and short.

The one exception I know is in a function name; look at BitConverter.ToInt64.

The reason for that is that long is not defined in CIL while int64 is.