Tüm bu sinir bozucu boş denetimleri işlemek ve varsa bir varsayılan değer eklemek için basit bir SessionItem yönetim sınıfı yazdım.C# - Bir satır içi yöntemi Func <T> parametresini nasıl tanımlarım?
Şimdipublic static T GetItem<T>(string key, Func<T> defaultValue)
{
if (HttpContext.Current.Session[key] == null)
{
HttpContext.Current.Session[key] = defaultValue.Invoke();
}
return (T)HttpContext.Current.Session[key];
}
, nasıl ben aslında bir satır içi yöntemi parametre olarak Func <T> geçen bu kullanıyorsunuz: İşte benim GetItem yöntemidir?
The ?? Sürüm, oturumdaki değeri ayarlamaz. –