class Program
{
static void Main()
{
string processName = "notepad";
try
{
var counter = new PerformanceCounter("Process", "Working Set - Private", processName);
float memoryBytes = counter.NextValue();
double memoryMB = memoryBytes / 1024 / 1024;
Console.WriteLine($"[{processName}] Memory (Task Manager 'Memory' column): {memoryMB:F1} MB");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
The memory value obtained using this code matches the value displayed in Task Manager’s Memory column, as shown in the screenshot below