Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a meaningful difference between "Double" and "double" in .Net?

As regards best practices, is there a meaningful difference between using:

Double d;

and

double d;

I know best practices are fraught with contradictions, so I know the answers may vary here. I just want to know the pragmatic difference between the two.

like image 664
IamIC Avatar asked Oct 16 '10 23:10

IamIC


People also ask

What is difference between double and double in C#?

There is no difference. double is just an alias for System. Double in C#.

Should I use double or decimal?

Use double for non-integer math where the most precise answer isn't necessary. Use decimal for non-integer math where precision is needed (e.g. money and currency). Use int by default for any integer-based operations that can use that type, as it will be more performant than short or long .

Is decimal same as double?

Decimal is for exact values. Double is for approximate values. Decimal is not for exact values. Decimal provides 28-29 decimal digits of accuracy according to the documentation.

What does double mean in C#?

The double is a fundamental data type built into the compiler and used to define numeric variables holding numbers with decimal points. C, C++, C# and many other programming languages recognize the double as a type. A double type can represent fractional as well as whole values.


2 Answers

There is no difference. double is just an alias for System.Double in C#.

Note that VB.NET doesn't have the same aliasing (int for System.Int32, double for System.Double, etc), so the aliasing is just applicable to C#, not .NET as a whole.

like image 135
Adam Lear Avatar answered Nov 15 '22 22:11

Adam Lear


No, there's no difference: double is a C# keyword that's an alias for the System.Double type.

like image 28
LukeH Avatar answered Nov 15 '22 23:11

LukeH