Print all distinct strings from a given array | C # program to implement the above approach ; Function to find the distinct strings from the given array ; Stores distinct strings from the given array ; Traverse the array ; If current string not present into the set ; Insert current string into the set ; Traverse the set DistString ; Print distinct string ; Driver code ; Stores length of the array
using System ; using System . Collections . Generic ; class GFG { static void findDisStr ( List < string > arr , int N ) { HashSet < string > DistString = new HashSet < string > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! DistString . Contains ( arr [ i ] ) ) { DistString . Add ( arr [ i ] ) ; } } foreach ( string a in DistString ) { Console . Write ( a + " ▁ " ) ; } } public static void Main ( String [ ] args ) { List < String > arr = new List < string > ( new [ ] { " Geeks " , " For " , " Geeks " , " Code " , " Coder " } ) ; int N = arr . Count ; findDisStr ( arr , N ) ; } }