Here is the full extended form of LINQ
Session.Keys
.Cast<string>()
.Where(k => !k.Contains("Selected")
.ToList()
.ForEach(k => Session[k] = null);
In this particular case, I find the combination of LINQ and foreachmore readable:
foreach (var key in Session.Keys.Cast<string>().Where(k => !k.Contains("Selected").ToList())) {
Session[key] = null;
}
source
share