我有一个要迁移到 Visual Studio 2013 的 WPF C# 项目。
以下代码编译正常,但现在失败了:
CultureInfo origCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentCulture = new CultureInfo(DILData.GetString("Config_Locale"));
声明如下:
using System.Globalization;
错误是:
Property or indexer 'System.Globalization.CultureInfo.CurrentCulture' cannot be assigned to -- it is read only
我以前没有遇到过这个问题。它缺少什么?
最佳答案
您正在针对旧的 .NET Framework 版本编译项目。尝试将其设置为 .NET 4.6 或更高版本。
In the .NET Framework 4.5.2 and earlier versions, the CurrentCulture property is read-only; that is, you can retrieve the property value, but you cannot set it. [..] Starting with the .NET Framework 4.6, the CurrentCulture property is read-write; you can both set and retrieve the property's value
来源:MSDN
关于只读分配的 C# 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47564140/