1.字符与字符数组进行比较,忽略大小写
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Contains { public class Program { static void Main(string[] args) { //字符与string数组对比,忽略大小写 string s = "a"; string a = "D"; string[] lst = { "A", "B", "C", "D", "E" }; try { //if (string.Equals(s,"A",StringComparison.OrdinalIgnoreCase)) for (int i = 0; i < lst.Length; i++) { if (string.Equals(s, lst[i].ToString(), StringComparison.OrdinalIgnoreCase)) { Console.WriteLine($"比较结果:s={s},lst={i.ToString()}"); } //else //{ // Console.WriteLine("0"); //} } } catch (Exception ex) { throw ex; } Console.ReadKey(); } } }