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 PandyaPosted Jan 12, 2018, 2:22 AM
Manav PandyaPosted Jan 12, 2018, 3:25 AM
saurabh choudharyPosted Jan 12, 2018, 3:15 AM