Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I declare in C sharp a List with nullable double values?

Tags:

c#

mono

nullable

The purpose is to enumerate the list and count how many nullable values I have, It will be used in order to test some Linq code because I lack of database. The thing is that no matter how I tried to define it I get from my compiler: "The type or namespace name List1' could not be found. Are you missing a using directive or an assembly reference?(CS0246)]".

thanks in advance.

like image 751
topless Avatar asked Feb 10 '10 00:02

topless


People also ask

How do you make a double nullable in C#?

Short answer: You can't. A double can only contain a valid double-precision floating point value. Save this answer.

Can list have null values C#?

In C# programs, a List reference can be null. This is not the same as it being empty and having zero elements.

How do you pass a double null value?

double is a primitive type, it cannot be null though. @Meenakshi6246, Double will always give you the value of “0” and we can't assign null value to double or system. DBNull to double.

How do you set a variable to null in C#?

In C#, you can assign the null value to any reference variable. The null value simply means that the variable does not refer to an object in memory. You can use it like this: Circle c = new Circle(42); Circle copy = null; // Initialized ... if (copy == null) { copy = c; // copy and c refer to the same object ... }


2 Answers

make sure you have:

using System.Collections.Generic;

then it should be as easy as:

List<double?> mylist = new List<double?>();
like image 179
John Boker Avatar answered Sep 29 '22 09:09

John Boker


Are you using mcs? It would be targeting the 1.1 runtime. that would explain "assembly reference not found" Try gmcs for targeting 2.0.

Of course, using System.Collections.Generic; is the cure for "missing using directive"

like image 39
Jimmy Avatar answered Sep 29 '22 09:09

Jimmy