Accepted style for long vs Int64 in C #?

I know that they are one and the same type of variable, but is there an accepted standard “style” for using long or Int64 ?

I would like to use the most common.

+42
c #
Apr 22 '13 at 17:16
source share
6 answers

All documentation from Microsoft and 99.999% (or so) of the code that you find on the Internet will use long . See, for example, the definition of a numeric data type in a C # link: http://msdn.microsoft.com/en-us/library/exx3b86w.aspx

In the end, this is the same problem using string or string . In general, lowercase names are used for value data types, such as numbers or characters, and for classes, uppercase names are used. C # Int64 provides a complex data type (structure with fields, properties, and methods, see Document here ) for a data type of type long (see Doc here ). In general, people do not use the Int64 class to call methods from this 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); 
+53
Apr 22 '13 at
source share

You will get so many different opinions on such a question, since they are exactly the same. So this is for you. Microsoft almost always uses long , int and short in its documentation and examples. This is just an alias in VB.NET and C #. Therefore, I believe that it is better to use them in this way.

  • long instead of Int64
  • int instead of Int32
  • short instead of Int16
+12
Apr 22 '13 at 17:18
source share

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

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

The first argument for using these keywords is that it comes with a language, so use it when writing a language.

The second argument for using these keywords is that you do not need to install using System; above your code file.

Another advantage could be that someone could create a new type called Int64 and put it somewhere in your namespace (I know ... that would be crazy). If your old code uses the Int64 type, your old code may stop functioning. If your old code used long (an alias for System.Int64 ), it will work fine.

+4
Apr 22 '13 at 17:26
source share

You should use long , int and short .

The only exception that I know is the name of the function; look at BitConverter.ToInt64 .

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

+3
Apr 22 '13 at 17:31
source share

I think it comes down to clarity and compatibility. Int16 , Int32 and Int64 more understandable than short , int and long . You know, just by looking at Int16 that it is 16 bits long.

+2
Apr 22 '13 at 17:23
source share

I think that in most cases it comes down to personal preference, but if you strictly say "C #" without specifying the underlying platform, I think a little differently. If you are developing to adhere to C # standards for portability across platforms and “future validation”, “long” would be a better way, as this is the actual construct in the language itself. "Int64" is the actual structure (System.Int64) within the framework.

0
Apr 22 '13 at 17:26
source share



All Articles