.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;
}

作者:D调灬仔
出处:https://www.cnblogs.com/chj929555796/
您的推荐是我最大的动力,如果觉得这篇文章对你有帮助的话,请点个“推荐”哦,博主在此感谢!
原文地址:https://www.cnblogs.com/chj929555796/p/6869532.html