在C#(.Net 3.5)中是否可以使用标准文字常量而不是"utf-8"?

Ham*_*jan 5 c# xml coding-style declaration utf-8

我想找到一个更好的方法来做到这一点:

XmlNode nodeXML = xmlDoc.AppendChild(
    xmlDoc.CreateXmlDeclaration( "1.0", "utf-8", String.Empty) );
Run Code Online (Sandbox Code Playgroud)

当我输入代码时,我不想考虑"utf-8"vs"UTF-8"vs"UTF8"vs"utf8".我想让我的代码更容易出现错别字.我确信某些标准库已声明"utf-8"为const/readonly字符串.我该怎么找到它?那么,"1.0"呢?我假设主要的XML版本也已在某处枚举.

谢谢!

Ben*_*n M 8

试试Encoding.UTF8.WebName.

  • static class ObsessiveCompulsive {public const string ONE_POINT_ZERO ="1.0"; } // 那里. (3认同)