pyCthon pyCthon - 1 month ago 11
C# Question

remove duplicates from two string arrays c#

How can i effectively remove duplicates from two string arrays? I want to remove all the duplicates from a

string[] a
that are in a separate
string[] b


for example

a = { "1", "2", "3", "4"};
b = { "3", "4", "5", "6"};


the result i am looking for would just be

c = { "5", "6"};

Answer

Enumerable.Except produces set difference of two sequences

var c = b.Except(a).ToArray(); // gives you { "5", "6" }
Comments