显示不完整的用户名

时间:2019-11-25 14:25:49

标签: c# wpf username

-----我正在使用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());
}

0 个答案:

没有答案