0

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 ??

3 Answers 3

2

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.
Sign up to request clarification or add additional context in comments.

Comments

2

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

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.