score:11

Accepted answer
src.Select(s => s ?? "NULL").ToList();

But what's wrong with using a foreach loop?

score:1

var list = new List<string>() { null, "test1", "test2" };
for (int i = 0; i < list.Count; i++)
{
    if (list[i] == null)
    {
        list[i] = "NULL";
    }
}

No foreach.


EDIT:

As no one seems to understand the meaning of this answer: LINQ does a foreach loop internally. You want to conditionally modify each item of a list? Then you have to enumerate it.

LINQ is here to help us write queries. Oh wait, this is the Q of LINQ.

LINQ is NOT here to modify existing lists. Just use a good old for loop here. You could of course create a new list based on the existing one with modified values (see best-voted answer), but I'm afraid you'll start using LINQ in a wrong way.


Related Query

More Query from same tag