How to get the index of each item that is null in a List<T> via Linq

Is there a way to get the index of each object in a List that is null?

For example:

List<string> list = new List<string>() { "1", null, "2", null, "3" };

Is it possible to get the information that list[1] and list[3] is null? In the best case I would get another list that provides me all the indexes that are null.

Jon Skeet
people
quotationmark

Yes, the simplest option would probably be:

var nullIndexes = list.Select((value, index) => new { value, index })
                      .Where(pair => pair.value == null)
                      .Select(pair => pair.index)
                      .ToList();

people

See more on this question at Stackoverflow