Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a C# delegate use the object type to be more generic?
    text
    copied!<p>I would like to create a delegate and a method that can be used to call any number of Web services that my application requires:</p> <p>Example:</p> <pre><code>public DateCheckResponseGetDate(DateCheckRequest requestParameters) { delegate object WebMethodToCall(object methodObject); WebMethodToCall getTheDate = new WebMethodToCall(WebServices.GetTheDate); return (DateCheckResponse)CallWebMethod(getTheDate , requestParameters); } public TimeCheckResponse GetTime(TimeCheckRequest requestParameters) { delegate object WebMethodToCall(object methodObject); WebMethodToCall getTheTime = new WebMethodToCall(WebServices.GetTheTime); return (TimeCheckResponse)CallWebMethod(getTheTime, requestParameters); } private object CallWebMethod(WebMethodToCall method, object methodObject) { return method(methodObject); } </code></pre> <p>But, unfortunately, when I try to compile, I get these errors:</p> <blockquote> <p>No overload for 'GetTheDate' matches delegate 'WebMethodToCall' No overload for 'GetTheTime' matches delegate 'WebMethodToCall'</p> </blockquote> <p>It seems like the delegate should work.</p> <p>WebServices.GetTheDate and WebServices.GetTheTime both take a single parameter (DateCheckRequest and TimeCheckRequest, respectively) and both return a value.</p> <p>So doesn't the delegate match the signature of the two web methods? (both accept and return types derived from object).</p> <p>Is it possible to use the object type to make a very reusable delegate in .NET 2.0?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload