How to get only the unique words from array of strings in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {
        String[ ] array = { "c#", "c", "c++", "vb", "java", "c#", "java", "c", "python" };

        IEnumerable<string> unique_words = array.Distinct();

        foreach (var word in unique_words)
            Console.WriteLine(word);
    }
}





/*
run:

c#
c
c++
vb
java
python

*/

 



answered Feb 10, 2022 by avibootz

Related questions

1 answer 121 views
1 answer 118 views
1 answer 147 views
1 answer 126 views
1 answer 153 views
1 answer 128 views
2 answers 161 views
...