public static string GetFoo() {
string source = GameInfoUtil.GetSource(repairRequest,() => {
return "0"; // this line gives error
});
.
.
MORE WORK, BUT WANT TO SKIP IT
}
public static string GetSource(WebRequest request, Action failureCallback) {
// DOING WORK HERE WITH REQUEST
if(WORK IS SUCCESSFULL) RETURN CORRECT STRING ELSE CALL ->
failureCallback();
return "";
}
我想做的事情smthing這樣的,但它給我的錯誤:使內回調返回
Error 2 Cannot convert lambda expression to delegate type 'System.Action' because some of the return types in the block are not implicitly convertible to the delegate return type.
Error 1 Since 'System.Action' returns void, a return keyword must not be followed by an object expression C:\Users\Jaanus\Documents\Visual Studio 2012\Projects\Bot\Bot\Utils\GameInfoUtil.cs 58 5 Bot
我想要做的,是當東西GameInfoUtil.GetSource
發生,它會叫出我代表,並且GetFoo
方法將返回並且不繼續工作。
是否有任何理由使用回調而不是普通的異常處理?這一切似乎都相當複雜 - 如果您對回調不太滿意,這尤其麻煩。 – 2013-03-16 08:50:36