In LINQ for objects, how to set the property of an object to null if it is equal to a "folder"?

I have a set of objects representing a folder structure.

I would like to set the FileExtension property to null if it is a folder.

This is, as far as I know. Can anyone help?

 var items = MyClass.All().ToList(); items.ForEach(x => x.FileExtension = string.empty) .Where(y => y.FileExtension == "folder") .ToList(); 
+4
source share
2 answers
 items .Where(i => i.FileExtension == "folder") .ToList() .ForEach(i => i.FileExtension = null); 
+6
source
 foreach(var item in items.Where( i => i.FileExtension == "folder" )) item.FileExtension = null; 
+5
source

All Articles