How can I make Array.Contains case-insensitive on a string array?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using the Array.Contains method on a string array. How can I make that case-insensitive? 回答1: array.Contains("str", StringComparer.OrdinalIgnoreCase); Or depending on the specific circumstance, you might prefer: array.Contains("str", StringComparer.CurrentCultureIgnoreCase); array.Contains("str", StringComparer.InvariantCultureIgnoreCase); 回答2: Some important notes from my side, or at least putting some distributed info at one place- concerning the tip above with a StringComparer like in: if (array.Contains("str", StringComparer