哪一個是最正確的代碼?哪個是檢查Null異常的正確方法?
if (HttpContext.Current.Response.Cookies[authCookieName] != null) {
HttpContext.Current.Response.Cookies[authCookieName].Value = "New Value";
}
或
if (HttpContext.Current != null)
if (HttpContext.Current.Response != null)
if (HttpContext.Current.Response.Cookies != null)
if (HttpContext.Current.Response.Cookies[authCookieName] != null)
HttpContext.Current.Response.Cookies[authCookieName].Value = "New Value";
BTW:HttpContext是一個類。如果一個類是空的,你肯定有麻煩了! :P – yfeldblum 2008-10-03 03:17:39
訣竅問題.... drat! – craigmoliver 2008-10-03 04:36:07