如标题所示,如何获取当前操作系统驱动器,以便将其添加到字符串中,例如:
MessageBox.Show(C:\ + "My Documents");
谢谢
最佳答案
添加对 System.IO 的引用:
using System.IO;
然后在你的代码中,写:
string path = Path.GetPathRoot(Environment.SystemDirectory);
让我们通过显示消息框来尝试一下。
MessageBox.Show($"Windows is installed to Drive {path}");
关于c# - 如何获取当前的 Windows 目录,例如C :\in C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7249715/