What is the assembly to use with Action<T>? I get an error on T not being accepted, that an assembly or namespace is missing.
Method(delegate { OnChange(); });
private static void MethodUsingOtherMethod(Action<T> action)
{
//TODO
}
If I put an extra <T> after MethodUsingOtherMethod then T is accepted, but then the argument in the delegate above is not recognized.
I want to use OnChange() in the second method, to be called from there.
Action<T>means that you need to pass a delegate accepting 1 argument of type T. So, if you want to pass OnChange, then you can just specifyActionwithout the T.That way, your code would look like this:
The error you got about T not being recognized is, because you didn’t declare your method as a generic method (done by putting the
<T>behind the method name). Because of that, the compiler didn’t recognize T as a type argument and tried to look up a type called T, which doesn’t exist.You might want to look up Generics to understand what’s going on there:
http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx