菜鸟的问题
好记性不如烂笔头~。~

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();

        }

    }
}
View Code

 

posted on 2019-10-24 18:25  ArSang-Blog  阅读(97)  评论(0编辑  收藏  举报