public static void Main()
{
// Instantiate delegate to reference UppercaseString method
Func<string, string> convertMethod = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
Console.WriteLine(convertMethod(name));
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
public TResult CallService<TServiceContract, TResult>(Func<TServiceContract, TResult> func) // func是委托形参
{
return ServiceHelper.CallService(func);
}
if(CallService<ITrafficCenterService, bool>(f => f.AskingCar(condition, out msg))) // 调用表达式用Lambda表达式作为委托方法