Question: I have a list that contains numeric values stored in a `List<string>`.

The data may contain some null values.

How can I convert `List<string>` to `List<double?>`?
This is my code:

```
List<double > d2 = d1.ConvertAll(item => double.Parse(item));

```

Answer: 
You didn't specify how you want to handle input that is not `null`, but can't be parsed. I offer you three solutions.

The first solution returns `null` for all `null` input and `string`s that can't be parsed to `double`.

```
var values =
    list.Select(
        s => {
            double value; 
            if(!Double.TryParse(s, out value)) {
                return (double?)null;
            }
            return value;
        }
    ).ToList();

```

Note that this will return `null` for `null` input *and* for `string`s that don't parse to `double`s.

The second solution will bomb if you have any `string`s that are not-null and can't be parsed:

```
var values = list.Select(s => s != null ? double.Parse(s) : (double?)null)
                 .ToList();

```

Again, note that this will *throw* an exception if you encounter any non-`null` `string`s that don't parse to `double`.

A third possibility is to elide non-null `string` that can't be parsed to `double`.

```
 var values =
     list.Select(
         s => {
             double value;
             if(s == null) {
                  return new { Parseable = true, Value = (double?)null) };
             }
             else if(!Double.TryParse(s, out value)) {
                  return new { Parseable = false, Value = (double?)null) };
             }
             else {
                  return new { Parseable = true, Value = value };
             }
      )
      .Where(x => x.Parseable)
      .Select(x => x.Value)
      .ToList();

```

I actually **strongly** advise against this. Silently ignoring errors is a huge source of bugs.
```
List<double?> result = myList.Select(n => n == null ? (double?)null : double.Parse(n)).ToList();

```