📌  相关文章
📜  使用环境类获取系统目录路径的C#程序

📅  最后修改于: 2022-05-13 01:54:31.333000             🧑  作者: Mango

使用环境类获取系统目录路径的C#程序

在 C# 中,环境类提供有关当前平台的信息并操作当前平台。它对于获取和设置各种与操作系统相关的信息很有用。我们可以使用它来检索命令行参数信息、退出代码信息、环境变量设置信息、调用堆栈信息的内容以及自上次系统启动以来的时间(以毫秒为单位)信息。通过使用一些预定义的方法,我们可以使用 Environment 类获取操作系统的信息。在本文中,我们将讨论如何获取系统目录的路径。所以我们使用环境类的SystemDirectory属性。该属性返回系统目录的完整路径

语法

返回类型:该属性的返回类型为字符串,该字符串表示系统目录的路径。

例子:

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


输出:

System Directory:
C:\Windows\system32