Answer the question
In order to leave comments, you need to log in
How to pass a function (method) as a parameter to a constructor?
Somewhere on the server side there is a function:
class RemoteServer
{
public int Value(string key)
{
return 1;
}
}
class Client
{
public Client(тут нужно указать функцию Value) // Возможно еще какие-то параметры будут
{
// ...
}
public int UseFuncClient()
{
// А здесь нужно будет как-то использовать указанную функцию.
}
}
Func<>
, but I can figure out how to do it the right way.
Answer the question
In order to leave comments, you need to log in
private Func<string, int> fn;
public Client(Func<string, int> fn)
{
this.fn = fn;
}
public int UseFuncClient()
{
fn("text");
}
var rs = new RemoteServer();
var cl = new Client(rs.Value);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question