How to check if a string contains identical digits in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
  
internal class StringContainIdenticalDigits_CSharp
{
    static bool isStringContainIdenticalDigits(string str) {
        char[] arr = str.ToCharArray();
          
        var hset = new HashSet<char>(arr);
  
        return hset.Count == 1;
    }
      
    public static void Main(string[] args)
    {
        string str = "88888888";
     
        if (isStringContainIdenticalDigits(str)) {
            Console.WriteLine("yes");
        } else {
            Console.WriteLine("no");
        }
    }
}
  
  
    
    
/*
run:
    
yes
    
*/

 



answered Feb 8, 2024 by avibootz
edited Jul 25, 2024 by avibootz

Related questions

1 answer 200 views
1 answer 198 views
1 answer 203 views
1 answer 196 views
1 answer 221 views
1 answer 211 views
1 answer 192 views
...