StringComparison.InvariantCultureIgnoreCase去了哪里?

时间:2013-01-30 09:37:43

标签: c# .net windows-store-apps

我正在将C#代码移植到Windows应用商店应用。令我惊讶的是,以下代码不再起作用了:

someString.Equals("someOtherString", StringComparison.InvariantCultureIgnoreCase)

InvariantCultureInvariantCultureIgnoreCase已从StringComparison删除(*)。

为什么吗

我该如何更换它?

编辑:(*)严格来说,它尚未被删除,它只是不可用用于Windows应用商店应用。结果是一样的:你不能使用它。

2 个答案:

答案 0 :(得分:17)

这些特定选项并没有消失,但Windows Store应用程序不支持它们。

如果您查看StringComparison Enumeration的MSDN,您会发现Portable库或.NET for Windows Store不支持这些特定选项。

Portable Library或Windows Store应用程序支持的唯一选项是:

  • 的CurrentCulture
  • CurrentCultureIgnoreCase
  • OrdinalIgnoreCase

我不能说出原因,但是没有选择"替换"因为框架内不存在这些值。您必须使用其他存在的选项之一,StringComparison.OrdinalIgnoreCase可能是最容易使用的选项。

答案 1 :(得分:5)

看起来它不支持Windows应用商店应用。

对于Windows应用商店应用,只能使用 绿色包 枚举;

enter image description here

一般来说,在这种情况下,人们使用了OrdinalIgnoreCase

https://github.com/loqu8/sqlite-net/commit/bfa04a6a40b4f62000bb9c57d5517643404c9109