c# - Is it possible to create a delegate for *any* Action? -
c# - Is it possible to create a delegate for *any* Action<T>? -
this question has reply here:
why covariance , contravariance not back upwards value type 4 answersi'm trying figure out why doesn't work:
public void defaultaction( object obj = null ){} public void start() { somereferencetype obj; defaultaction( obj ); //works int i; string s; defaultaction( ); //works defaultaction( s ); //works } //however... public event action onnullaction = defaultaction; //works public event action<somereferencetype> onobjectaction = defaultaction; //works public event action<int> onintaction = defaultaction; //doesn't work!! trying bind void(object) action<valuetype> throws parameter mismatch error, though can phone call function straight int/string/bool have you. there mysterious boxing/unboxing happening? , regardless, possible create delegate can respond action<t>?
just create generic
public void defaultaction<t>(t param) { } c# events parameters delegates action
Comments
Post a Comment