How to check if all strings in an array are equal in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    public static bool allStringsAreEqual(string []arr) {
        return arr.Select(s => s.ToLower()).Distinct().Count() == 1;
    }
    static void Main() {
        string [] arr = {"c#", "c#", "c#", "c#"}; 

        if (allStringsAreEqual(arr))
            Console.Write("Yes");
        else
            Console.Write("No");
    }
}




/*
run:
            
Yes
            
*/

 



answered Dec 6, 2021 by avibootz
...