The most correct/idiomatic solution (if you cannot avoid having a null collection to begin with) is to use an if:
if(list != null)
foreach(var str in list)
Console.WriteLine(str);
Putting the if into a lambda isn't going to make anything any easier. In fact, it'll only create more work.
Of course if you really hate using an if you can avoid it, not that it'll really help you much:
foreach(var str in list??new List<string>())
Console.WriteLine(str);
foreach(var str in list == null ? new List<string>() : list)
Console.WriteLine(str);
You could emulate the more functional style Maybe concept with a method that invokes an action if the object isn't null, not that this is really any easier than a null check when dealing with actions instead of functions:
public static void Maybe<T>(this T obj, Action<T> action)
{
if (obj != null)
action(obj);
}
strList.Maybe(list =>
foreach(var str in list)
Console.WriteLine(str));
null.strListis null, or that an element instrListis null?strList.ForEach(Console.WriteLine), sinceConsole.WriteLineis already a method that takes a string and returns void.strList?.ForEach (x => Console.WriteLine(x)) ;should work