The question is simple.
For example, there are two sets.
List <string> listA = new List <string> {"a", "B", "c", "d", "e "};
List <string> listB = new List <string> {"a", "B", "f "};
You need to find the elements that exist in listA and do not exist in listB.
Method 1:
List <string> B = new List <string> ();
Foreach (var item in listA)
{
If (! ListB. Contains (item ))
B. Add (item );
}
Implementation Method 2
IEnumerable <string> result = listA. Counter T <string> (listA. Intersect <string> (listB ));
Method 2 is equivalent
ISet <string> setA = new HashSet <string> (listA );
ISet <string> setB = new HashSet <string> (listB );
SetA. receivtwith (setB );
Implementation Method 3: If listA and listB are ordered, it can be processed in a simpler way.
[Csharp]
Static List <T> extends twith <T> (List <T> from, List <T> doesn T) where T: IComparable
{
List <T> resut = new List <T> ();
Int fromindex, tindex, copyindex;
Fromindex = tindex = copyindex = 0;
While (fromindex <from. Count) & (using tindex <using T. Count ))
{
Int compar = (IComparable) from [fromindex]). CompareTo (partition T [partition tindex]);
If (compar <0)
{
Fromindex ++;
}
Else if (compar> 0)
{
Using tindex ++;
}
Else if (compar = 0)
{
If (fromindex> copyindex)
CopyData (from, resut, copyindex, fromindex );
Fromindex ++;
Copyindex = fromindex;
}
}
CopyData (from, resut, copyindex, from. Count );
Return resut;
}
Static void CopyData <T> (List <T> from, List <T> to, int startindex, int endindex)
{
If (from = null | to = null | startindex <0 | endindex <0 | endindex <= startindex) return;
To. AddRange (from. Where (data, index) => index> = startindex & index <endindex ));
}
Call method: List <string> temp = effectwith <string> (new List <string> () {"a", "B", "c", "d ", "e"}, new List <string> () {"a", "B", "f "});
List <int> a = inclutwith <int> (new List <int> () {1, 3, 4, 7, 9, 11}, new List <int> () {4, 7 });
From the column dz45693