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

1 Answer

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

public class Program
{
    public static void Main()
    {
        string s1 = "c# c++ java c php vb.net c javascript";
        string s2 = "c python vb.net c++ c# vb.net java node.js";

        var words = (s1 + " " + s2).Split();

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

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





/*
run:

c#
c++
java
c
php
vb.net
javascript
python
node.js

*/

 



answered Feb 10, 2022 by avibootz

Related questions

1 answer 143 views
1 answer 125 views
1 answer 118 views
1 answer 128 views
1 answer 146 views
1 answer 153 views
1 answer 123 views
...