【问题标题】:Why does the .NET runtime add underscores to my string?为什么 .NET 运行时会在我的字符串中添加下划线?
【发布时间】:2011-09-16 07:23:33
【问题描述】:

我以 C# 方式 (Properties.Settings.Default.Save();) 存储我的应用程序设置。然后设置由 C# 运行时存储在文件夹中:

C:\Users\UserName\AppData\Local\My_Company_Name

奇怪的是,我在 Visual Studio ([assembly: AssemblyCompany("My Company Name")]) 中输入了“我的公司名称”作为公司属性。

那么,下划线从何而来?我见过其他应用创建文件夹带有空白...

【问题讨论】:

    标签: c# .net settings


    【解决方案1】:

    问题是您要添加一个名为“我的公司名称”的property。这不是 C# 中的有效 member 名称,因此它会自动为您转换为有效名称:“My_Company_Name”

    如果您创建一个名为“我的项目”的新项目,也会发生同样的事情。您项目的默认namespace 不会是“我的项目”,因为它无效。 VS 将为您创建的默认namespace 将是“My_Project”。

    【讨论】:

    • +1。同意。只需从here 中添加报价Each application setting must have a unique name; the name can be any combination of letters, numbers, or an underscore that does not start with a number, and cannot contain spaces
    猜你喜欢
    • 1970-01-01
    • 2019-03-19
    • 2017-12-23
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 2011-04-07
    相关资源
    最近更新 更多