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 107 views
1 answer 123 views
1 answer 112 views
1 answer 127 views
1 answer 145 views
1 answer 126 views
1 answer 119 views
...