Anuya
Anuya

Reputation: 8350

Comparing two arraylist in c# windows application

I have the arraylist which has some process names like "Notepad", "mspaint"

I want to check the values of above arraylist against the following :

Process[] Procs = Process.GetProcesses();

If the process "Notepad" is not there in Procs, then i want to use that value for further requirement.

How do i find the value of my arraylist which is missing in Procs ??

Upvotes: 0

Views: 1143

Answers (3)

Konamiman
Konamiman

Reputation: 50273

Or you could use the Except method provided by LINQ. But if you are using Arraylist instead of List<>, I guess you are using .NET 1.

Upvotes: 0

Nils
Nils

Reputation: 9941

1) Go through the list one-by-one using ArrayList.Contains

2) If LINQ is available use the set difference: Except()

Upvotes: 2

Andrew Keith
Andrew Keith

Reputation: 7563

There are smarter answers, but i will post a naive one because its easier to understand

List<string> myprocs; // populated with process names
Process[] Procs = Process.GetProcesses();
foreach(Process proc in Procs)
{
  if(myprocs.Contains(proc.ProcessName))
  {
     myprocs.Remove(proc.ProcessName);
  }
}
// whatever that is left over in myprocs at this point is your remainder process names.

Upvotes: 2

Related Questions