ممکن میباشد بارها منظور باشید دولیست را با هم گردآوری طراحی اپلیکیشن یا این که از هم معدود نمایید شایسته ترین خط مش override کردن operator + و - میباشد
using System.Linq;
namespace System.Collections.Generic
{
public class MyList : List
{
public MyList() : base()
{
}
public MyList(IEnumerable source) : base(source)
{
}
public static MyList operator +(MyList list1, MyList list2)
{
list1.AddRange(list2);
var tmp = list1.Distinct();
MyList tmpresult = new MyList(tmp);
return tmpresult;
}
public static MyList operator -(MyList list1, MyList list2)
{
MyList tmpresult = new MyList();
foreach (var i in list1)
{
if (!list2.Contains(i))
tmpresult.Add(i);
}
return tmpresult;
}
}
}