PrepAway - Latest Free Exam Questions & Answers

What should you do?

You are required to retrieve and display the names of all processes that are currently running in memory.
What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Use the following code:
foreach (Process curProcess in Process.GetSystemProcesses())
Console.WriteLine (curProcess.ProcessName);

B.
Use the following code:
foreach (Process curProcess in Process.GetAllProcesses())
Console.WriteLine (curProcess.ProcessName);

C.
Use the following code:
foreach (Process curProcess in Process.GetProcesses())
Console.WriteLine (curProcess.ProcessName);

D.
Use the following code:
foreach (Process curProcess in Thread.GetProcesses())
Console.WriteLine (curProcess.ProcessName);

Explanation:
The GetProcesses method creates and returns an array of Process objects representing all currently running processes in memory.
Because this method invocation does not contain a computer name, the local machine is assumed.
The curProcess variable is reassigned to a Process object with each iteration. The ProcessName property of the Process object retrieves the system name of the process.
The WriteLine method of the Console class outputs the process name to the console. Because the WriteLine method outputs a line return, each process name will be on a separate line in the Console window.
Incorrect Answers:
A, B: The GetSystemProcesses and GetAllProcesses methods do not exist in the Process class.
D: There is no such method as the GetProcesses method in the Thread class.

One Comment on “What should you do?


Leave a Reply