How to get only the unique words from a string in C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;
 
class Program
{
    static void Main() {
        string s = "csharp cpp csharp c++ java c python Csharp c cpp php c++ java";
  
        var words = s.Split();
 
        IEnumerable<string> unique_words = words.Distinct();  
           
        foreach (var word in unique_words) {
            Console.WriteLine(word);

        }
    }
}
  
  
  
  
/*
run:
  
csharp
cpp
c++
java
c
python
Csharp
php
  
*/

 



answered Feb 10, 2022 by avibootz

Related questions

1 answer 260 views
1 answer 227 views
1 answer 262 views
2 answers 279 views
2 answers 257 views
2 answers 243 views
1 answer 203 views
...