开发者

Comparing two arraylist in c# windows application

I have the arraylist which has some process names like 开发者_JAVA技巧"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 ??


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.


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜