PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are creating an application that lists processes on remote computers.
The application requires a method that performs the following tasks: Accept the remote computer name as a string parameter named strComputer.
Return an ArrayList object that contains the names of all processes that are running on that computer.
You need to write a code segment that retrieves the name of each process that is running on the remote computer and adds the name to the ArrayList object.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
ArrayList^ al = gcnew ArrayList();
array procs = Process::GetProcessesByName(strComputer);
for each (Process^ proc in procs) {
al->Add(proc);
}

B.
ArrayList^ al = gcnew ArrayList();
array procs = Process::GetProcesses(strComputer);
for each (Process^ proc in procs) {
al->Add(proc);
}

C.
ArrayList^ al = gcnew ArrayList();
array procs = Process::GetProcessesByName(strComputer);
for each (Process^ proc in procs) {
al->Add(proc->ProcessName);
}

D.
ArrayList^ al = gcnew ArrayList();
array procs = Process::GetProcesses(strComputer);
for each (Process^ proc in procs) {
al->Add(proc->ProcessName);

Explanation:
Call Processes.GetProcesses() supplying the name of the computer and then iterate through the returned collection of processes adding the process name to the arraylist.
A & C use GetProcessByName() and return processes on the current computer only. B adds the entire process to the arraylist rather than just the process name.

One Comment on “Which code segment should you use?


Leave a Reply