C# ForEach extension for IEnumerable type.
Please follow the instructions on NuGet documentation.
Search for IEnumerable.ForEach
and install the package to your project.
Launch Visual Studio 2015+ and then launch Package Manager Console.
PM> Install-Package IEnumerable.ForEach
PS> dotnet add package IEnumerable.ForEach
using IEnumerable.ForEach;
The following program deletes all the files in a directory without the need for a foreach
loop -
using System;
using System.IO;
using IEnumerable.ForEach;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
var dest = @"F:\demo\folder";
if (Directory.Exists(dest))
{
Console.WriteLine("Deleting files...");
Directory.GetFiles(dest).ForEach(e => File.Delete(e));
}
}
}
}