using System;
using System.Collections.Generic;
using System.Text;
namespace GrenListDemo
{
public class GreListComparer<T>
{
public static void Compare(List<T> ListA, List<T> ListB, out List<T> AandBList, out List<T> AOnlyList, out List<T> BOnlyList)
{
AandBList = new List<T>();
AOnlyList = new List<T>(ListA);
BOnlyList = new List<T>(ListB);
for (int i = 0; i < AOnlyList.Count; i++)
{
for (int j = 0; j < BOnlyList.Count; j++)
{
if (AOnlyList[i].Equals(BOnlyList[j]))
{
AandBList.Add(AOnlyList[i]);
AOnlyList.RemoveAt(i--);
BOnlyList.RemoveAt(j--);
break;
}
}
}
}
public static void Compare2(List<T> ListA, List<T> ListB, ref List<T> AandBList, ref List<T> AOnlyList, ref List<T> BOnlyList)
{
AandBList = new List<T>();
for (int i = 0; i < AOnlyList.Count; i++)
{
for (int j = 0; j < BOnlyList.Count; j++)
{
if (AOnlyList[i].Equals(BOnlyList[j]))
{
AandBList.Add(AOnlyList[i]);
AOnlyList.RemoveAt(i--);
BOnlyList.RemoveAt(j--);
break;
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
List<int> listA = new List<int>();
listA.Add(1);
listA.Add(2);
listA.Add(3);
List<int> listB = new List<int>();
listB.Add(2);
listB.Add(3);
listB.Add(4);
List<int> AORB;
List<int> Aonly;
List<int> Bonly;
GreListComparer<int>.Compare(listA, listB,out AORB,out Aonly,out Bonly);
Console.WriteLine(AORB.Count.ToString());
Console.WriteLine(Aonly.Count.ToString());
Console.WriteLine(Bonly.Count.ToString());
List<int> listA2 = new List<int>();
listA2.Add(1);
listA2.Add(2);
listA2.Add(3);
List<int> listB2 = new List<int>();
listB2.Add(2);
listB2.Add(3);
listB2.Add(4);
List<int> AORB2=new List<int>();
List<int> Aonly2 = new List<int>(listA2);
List<int> Bonly2 = new List<int>(listB2);
GreListComparer<int>.Compare2(listA2, listB2, ref AORB2, ref Aonly2, ref Bonly2);
Console.WriteLine(AORB2.Count.ToString());
Console.WriteLine(Aonly2.Count.ToString());
Console.WriteLine(Bonly2.Count.ToString());
List<string> listA3 = new List<string>();
listA3.Add("pp");
listA3.Add("xy");
listA3.Add("xyz");
List<string> listB3 = new List<string>();
listB3.Add("xyz");
listB3.Add("hj");
listB3.Add("ff");
List<string> AORB3 = new List<string>();
List<string> Aonly3 = new List<string>(listA3);
List<string> Bonly3 = new List<string>(listB3);
GreListComparer<string>.Compare2(listA3, listB3, ref AORB3, ref Aonly3, ref Bonly3);
Console.WriteLine(AORB3.Count.ToString());
Console.WriteLine(Aonly3.Count.ToString());
Console.WriteLine(Bonly3.Count.ToString());
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace GrenListDemo
{
public class GreListComparer<T>
{
public static void Compare(List<T> ListA, List<T> ListB, out List<T> AandBList, out List<T> AOnlyList, out List<T> BOnlyList)
{
AandBList = new List<T>();
AOnlyList = new List<T>(ListA);
BOnlyList = new List<T>(ListB);
for (int i = 0; i < AOnlyList.Count; i++)
{
for (int j = 0; j < BOnlyList.Count; j++)
{
if (AOnlyList[i].Equals(BOnlyList[j]))
{
AandBList.Add(AOnlyList[i]);
AOnlyList.RemoveAt(i--);
BOnlyList.RemoveAt(j--);
break;
}
}
}
}
public static void Compare2(List<T> ListA, List<T> ListB, ref List<T> AandBList, ref List<T> AOnlyList, ref List<T> BOnlyList)
{
AandBList = new List<T>();
for (int i = 0; i < AOnlyList.Count; i++)
{
for (int j = 0; j < BOnlyList.Count; j++)
{
if (AOnlyList[i].Equals(BOnlyList[j]))
{
AandBList.Add(AOnlyList[i]);
AOnlyList.RemoveAt(i--);
BOnlyList.RemoveAt(j--);
break;
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
List<int> listA = new List<int>();
listA.Add(1);
listA.Add(2);
listA.Add(3);
List<int> listB = new List<int>();
listB.Add(2);
listB.Add(3);
listB.Add(4);
List<int> AORB;
List<int> Aonly;
List<int> Bonly;
GreListComparer<int>.Compare(listA, listB,out AORB,out Aonly,out Bonly);
Console.WriteLine(AORB.Count.ToString());
Console.WriteLine(Aonly.Count.ToString());
Console.WriteLine(Bonly.Count.ToString());
List<int> listA2 = new List<int>();
listA2.Add(1);
listA2.Add(2);
listA2.Add(3);
List<int> listB2 = new List<int>();
listB2.Add(2);
listB2.Add(3);
listB2.Add(4);
List<int> AORB2=new List<int>();
List<int> Aonly2 = new List<int>(listA2);
List<int> Bonly2 = new List<int>(listB2);
GreListComparer<int>.Compare2(listA2, listB2, ref AORB2, ref Aonly2, ref Bonly2);
Console.WriteLine(AORB2.Count.ToString());
Console.WriteLine(Aonly2.Count.ToString());
Console.WriteLine(Bonly2.Count.ToString());
List<string> listA3 = new List<string>();
listA3.Add("pp");
listA3.Add("xy");
listA3.Add("xyz");
List<string> listB3 = new List<string>();
listB3.Add("xyz");
listB3.Add("hj");
listB3.Add("ff");
List<string> AORB3 = new List<string>();
List<string> Aonly3 = new List<string>(listA3);
List<string> Bonly3 = new List<string>(listB3);
GreListComparer<string>.Compare2(listA3, listB3, ref AORB3, ref Aonly3, ref Bonly3);
Console.WriteLine(AORB3.Count.ToString());
Console.WriteLine(Aonly3.Count.ToString());
Console.WriteLine(Bonly3.Count.ToString());
Console.ReadKey();
}
}
}