Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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.

Syntax:

Environment.ProcessorCount

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

Example:

C#




// 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);
}
}


Output:

Total number of processors in current process is 4

Last Updated : 24 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads