Hi, I have recently started on C# and getting doubts. Can anyone help me out in understanding the below code, specialy the importance of get accessor with session. Any help will be appreciated. Thanks.
using System.Web;
using System.Web.SessionState;
using System.Collections.Generic;
public static class ExampleSession
{
private static HttpSessionState session { get { return HttpContext.Current.Session; } }
public static string UserName
{
get { return session["username"] as string; }
set { session["username"] = value; }
}
public static List ProductsSelected
{
get
{
if (session["products_selected"] == null)
session["products_selected"] = new List();
return (List)session["products_selected"];
}
}
}

Manav PandyaRank #166 · 14.3K reputationPosted Jan 11, 2018, 9:22 PM EST
saurabh choudhary14 reputationPosted Jan 11, 2018, 10:15 PM EST
Manav PandyaRank #166 · 14.3K reputationPosted Jan 11, 2018, 10:25 PM EST