Let's test it:
public static void TestMe<T>(Action<List<T>> action)
{
List<T> collection = new List<T>();
collection.Add((T)(object)"123"); //I do not know, how you fill the collection
action(collection);
}
You can use lamda expression to specify the action;
l
here is just a parameter:TestMe<string>(l => l.ForEach(s => Console.WriteLine(s))); //outputs: 123
You may specify a method with the necessary signature:
public static void Foo<T>(List<T> list) { list.ForEach(s => Console.WriteLine(s)); }
and call
TestMe
then:TestMe<string>(Foo); //outputs: 123
Both these examples show that your TestMe
does not require the List<T>
to be called and do use the collection specified within the TestMe
method.