Skip to content
Related Articles
Open in App
Not now

Related Articles

C# Program to Get Number of Processors of Current Machine using Environment Class

Improve Article
Save Article
  • Last Updated : 24 Oct, 2021
Improve Article
Save Article

Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since last system boot in milliseconds information. In this article, we will discuss how to get the number of processors of the current machine. So, we use the ProcessorCount property of the Environment class. This property returns the count of processors present in the current process.



Return Type: The return type of this property is 32-bit signed integer.



// C# program to find the number of processors of 
// the current machine using Environment class
using System;
class GFG{
static public void Main()
    // Declare a variable
    int result;
    // Now find the number of processors 
    // of the current machine
    // Using ProcessorCount property 
    result = Environment.ProcessorCount;
    // Display the result
    Console.WriteLine("Total number of processors "
                      "in current process is " + result);


Total number of processors in current process is 4
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!