-----我正在使用C#WPF .NET Framework 4.7.2 -----
我在PC上使用用户名“ JD_1609”,为什么当我使用Environment.UserName
(->写入标签)时,标签中的名称仅为“ JD1609”,但是当我将其写入桌面上的txt文件时通常是“ JD_1609” ???为什么缺少下划线?
我的代码:
UserLabelC.Content = Environment.UserName;
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
filePath += @"\File.txt";
using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
{
file.WriteLine(UserLabelC.Content.ToString());
}