Open In App

C# Program to Get the Path of System Directory Using Environment Class

Improve
Improve
Like Article
Like
Save
Share
Report

In C#, 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 it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. In this article, we will discuss how to get the path of the system directory. So we use the SystemDirectory property of the Environment Class. This property returns the full path of the directory of the system

Syntax:

Environment.SystemDirectory

Return Type: The return type of this property is a string and this string represents the path of the system directory.

Example:

C#




// C# program to find the path of system directory
using System;
 
class GFG{
 
static public void Main()
{
 
    // Declaring a variable
    string resultDir = "";
 
    // Now finding the path of system directory
    // Using the SystemDirectory property of
    // the Environment class
    resultDir = Environment.SystemDirectory;
 
    // Displaying the result
    Console.WriteLine("System Directory:" + resultDir);
}
}


Output:

System Directory:
C:\Windows\system32

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