Use the Environment.ProcessorCount to get the total number of cores on a computer −
Environment.ProcessorCount
The following is the code that displays the total number of cores on a computer in C# −
Example
Using System;
namespace Demo {
class Program {
static void Main(string[] args) {
Console.WriteLine(Environment.ProcessorCount);
}
}
}