Determine if a string has all Unique Characters | C # program to illustrate String with unique characters using set data structure ; Inserting character of String into set ; If length of set is equal to len of String then it will have unique characters ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static bool uniquechars ( String str ) { HashSet < char > char_set = new HashSet < char > ( ) ; for ( int c = 0 ; c < str . Length ; c ++ ) { char_set . Add ( str ) ; } if ( char_set . Count == str . Length ) { return true ; } else { return false ; } } public static void Main ( String [ ] args ) { String str = " GeeksforGeeks " ; if ( uniquechars ( str ) ) { Console . Write ( " The ▁ String ▁ " + str + " ▁ has ▁ all ▁ unique ▁ characters STRNEWLINE " ) ; } else { Console . Write ( " The ▁ String ▁ " + str + " ▁ has ▁ duplicate ▁ characters STRNEWLINE " ) ; } } }