public partial class Test : Page { private string item; public string Item { get { if (!string.IsNullOrEmpty(item)) return item; return (item = (string)(Session["item"] ?? string.Empty)); } set { Session["Item"] = this.item = value; } } protected override void OnInit(EventArgs e) { base.OnInit(e); this.Item = DateTime.Now.ToString("hh:mm:ss"); } protected override void OnLoad(EventArgs e) { this.Response.Write(this.Item); } }
Other Types:
int? time; public int Time { get { if (this.time.HasValue) return time.Value; return (time = (int)(Session["time"] ?? 0)).Value; } set { Session["time"] = this.time = value; } } bool? isLive; public bool IsLive { get { if (this.isLive.HasValue) return isLive.Value; return (isLive = (bool)(Session["isLive"] ?? false)).Value; } set { Session["isLive"] = this.isLive = value; } }
No comments:
Post a Comment