Please note that LINQ is for querying, projecting, and aggregating. You are doing something with a side effect here, and LINQ is not suitable for this. So, I separate the request part from the side effective part.
private void KillProcessesWithName(string processName) { var processesToKill = Process.GetProcesses() .Where(p => p.ProcessName == processName); foreach(var process in processesToKill) { process.Kill(); } }
Perhaps the LINQified version is better, and I would keep it as it is.
jason source share