Compare two List<string> Get uncommon from both list

Sudip Bhatt 2,276 Reputation points
2020-12-18T17:52:11.593+00:00

I tried this way but not getting desired result

        List<string> _lst1 = new List<string>();
        _lst1.Add("tab1");
        _lst1.Add("tab2");
        _lst1.Add("common");

        List<string> _lst2 = new List<string>();
        _lst2.Add("tab1");
        _lst2.Add("tab4");
        _lst2.Add("common");

        var _lst3 = _lst1.Except(_lst2);
        var _lst4 = _lst2.Except(_lst1);
        var resultList = _lst3.Concat(_lst4).ToList();

I am getting Result is : tab2,common,tab4

but in two list the uncommon is tab2 & tab4. so i want to get uncommon from both list.....what logic i should use? thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,892 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 117.2K Reputation points
    2020-12-18T19:34:17.85+00:00

    Replace the second list1.Add(“common”) with list2.Add(“common”).

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.