首页 > 代码库 > 声明变量,一定要用 var!

声明变量,一定要用 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!

声明变量,一定要用 var!