TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
saurabh choudhary
NA
13
1.4k
Use of Get Set property with Session Sate.
Jan 12 2018 2:00 AM
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<string> ProductsSelected
{
get
{
if (session["products_selected"] == null)
session["products_selected"] = new List<string>();
return (List<string>)session["products_selected"];
}
}
}
Reply
Answers (
3
)
How to get CheckedListBox values from DataBase?
Converting Celsius to Farenheit