如何在 C# 中获取 Mac OSX 当前用户的目录?

Sam*_*art 3 c# macos

现在我有:

s = @"/Users/minisquad1/Pictures/";
Run Code Online (Sandbox Code Playgroud)

这在我的电脑上运行得很好。如果我可以访问当前用户的图片文件夹,我会感到更安全,因为现在它显然只能在我的计算机上使用。

我不知道该怎么做,有人有想法吗?我正在寻找类似的东西:

s = @"/Users/%currentuser%/Pictures/";
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?

Chr*_*ris 5

您应该考虑使用Environment.SpecialFolderenumEnvironment.SpecialFolder.Personal应该让你获得当前用户的主目录。还有一个MyPictures值可以节省您的打字时间。

string s = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
Run Code Online (Sandbox Code Playgroud)