I want to create an extension method that runs on a List and accept another list:
public static void Charge<T, S>(this ICollection<T> targetList, ICollection<S> sourceList) where T : class, new()
{
if (targetList == null || sourceList == null)
throw new NullReferenceException();
targetList = new List<T>();
foreach (var item in sourceList)
{
T t = new T();
//do work on t
targetList.Add(t);
}
}
however when I call it like this:
var targetList = new List<Item>();
targetList.Charge(sourceList);
the targetList
doesn't change (items count = 0)