Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does double? mean in C#? [duplicate]

Tags:

Possible Duplicate:
C# newbie: what’s the difference between “bool” and “bool?” ?

Hi, While reading the code of the NUnit project's assert class, I came across this particular construct -

public static void AreEqual(double expected, double? actual, double delta)
{
     AssertDoublesAreEqual(expected, (double)actual, delta ,null, null);
}

In this function the second input parameter is entered as double?. The interesting thing is that this code compiles without issue in VS2010 (C# 4.0). Anyone know why this is NOT throwing an error ? Why is double? considered a valid keyword and is there any special significance to the ?.

like image 598
Nikhil Avatar asked Jun 07 '10 10:06

Nikhil


People also ask

What is the double command in C?

Updated on April 27, 2019. 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.

What is double in data type?

This data type is widely used by programmers and is used to store floating-point numbers. All real numbers are floating-point values. A variable can be declared as double by adding the double keyword as a prefix to it. You majorly used this data type where the decimal digits are 14 or 15 digits.

Is double A keyword in C?

Keywords double and float are used for declaring floating type variables. For example: float number; double longNumber; Here, number is a single-precision floating type variable whereas, longNumber is a double-precision floating type variable.

What is a double programming?

Double programming is widely accepted as the gold standard of program validation and quality. In double programming, two programmers work independently from the same specifications. When they are done, they compare output, which may be a dataset, listing, table, or graph.


2 Answers

double? is just shorthand for Nullable<double>; basically, a double that can be null. But the code is not very safe. If actual is null, (double)actual will throw an exception.

like image 91
Gorpik Avatar answered Oct 12 '22 10:10

Gorpik


It's a nullable type. So it's a double that can also be null.

See here for more info.

like image 29
Hans Olsson Avatar answered Oct 12 '22 09:10

Hans Olsson