.net判断多个字符串是否相等

 

//是否存在相同

  string a = "1,1,1";
            string[] str = a.Split(',');
            if (str.Distinct().Count() == 1)
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("n");
            }

 

//是否全部相同

static void Main(string[] args)
{
string str = "信息技术,信息技术,信息技术";
bool bl = Check(str);
Console.Write(bl);
}

static bool Check(string str) {
bool b=true;
List<string> temp = str.Split(',').ToList();
string tempStr = temp[0];
foreach (var item in temp)
{
if (item != tempStr) {
b = false;
break;
}
}
return b;
}

 

posted @ 2017-05-17 21:02  D调灬仔  阅读(1129)  评论(0编辑  收藏  举报

作者D调灬仔

出处:https://www.cnblogs.com/chj929555796/

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!