Reputation: 176
I have following code. dont have any clue why I am getting this error - Delegate Function doesnot take 1 arguments.
I am implementing a global Response handler which will be called by saveral requests.
Here is the HandleResponse function:
Response<T> HandleResponse<T>(Func<Response<T>> func)
{
try
{
Response <T> response = func();
if(response != null)
{
return response;
}
else
{
//display response.message
return default(Response<T>);
}
}
catch(ConnectionException e)
{
// func = e.Message.ToString();
Console.WriteLine(e.Message);
return default(Response<T>);
}
}
And here is my Calling Function:
Request.MyRequest request = new
Request.MyRequest()
{
param1= comment, param2 = users
};
SomeResponse response = HandleResponse<SomeResponse>(x => client.DoRequest(request, revision.Name, revision.RevisionNumber));
I am a C++ developer and very new to C#. I am not sure why I am getting this error. Please someone explain.
Thanks in advance.
Upvotes: 0
Views: 249
Reputation: 2985
By using x => client.DoRequest()
you are calling the delegate with 1 Parameter (the x
before =>
).
But your delegate has no parameters so you have to call it like this
() => client.DoRequest()
Upvotes: 2