只读分配的 C# 错误

标签 c# wpf

我有一个要迁移到 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/

相关文章:

c# - 如何使用扩展方法公开记录属性并将该属性设为私有(private)

c# - 将 AutoSuggestBox 添加到汉堡导航的正确方法?

c# - 在 C# 中从 Visual Dataflex 6 读取数据

c# - 是否有 IValueConverter 执行 if-then

c# - C# 中的简单依赖属性和 UserControl 问题

c# - 在应用程序栏项目中添加/删除事件订阅者?

c# - 如何更改 wpf listview 项目文本

c# - 在 WPF 中使用系统图标作为应用程序图标

C# 文本框中没有 PasswordChar 字段

c# - MS C# 编译器和非优化代码