声明变量,一定要用 var!

public static T TryGet<T>(Func<T> func, T ifError = default(T)) {
    try {
        return func();
    } catch {
        return ifError;
    }
}

string a;
try{ a = doooooooooo(); } catch { a = "wrewre"; }

//this is shit!

var a = TryGet(doooooooooo, "wrewre");

//great!

posted @ 2016-11-22 03:17  大胡子毛绒老头  阅读(184)  评论(0编辑  收藏  举报