Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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.

like image 281
Kyle Avatar asked Apr 22 '13 17:04

Kyle


People also ask

Is Int64 same as long?

In C#, long is mapped to Int64. It is a value type and represent System. Int64 struct. It is signed and takes 64 bits.

What is Int64 in C#?

Int64 is an immutable value type that represents signed integers with values that range from negative 9,223,372,036,854,775,808 (which is represented by the Int64. MinValue constant) through positive 9,223,372,036,854,775,807 (which is represented by the Int64. MaxValue constant.

Is Int32 A Long?

An int (aka System. Int32 within the runtime) is always a signed 32 bit integer on any platform, a long (aka System.


2 Answers

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); 
like image 61
Julián Urbano Avatar answered Sep 21 '22 14:09

Julián Urbano


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
like image 32
phadaphunk Avatar answered Sep 22 '22 14:09

phadaphunk