A Scheme for Representing Session State

Session state is typically represented as a Dictionary with string keys and arbitrary values, such as the following:

static Dictionary<string, object> sessionState = new Dictionary<string, object>();

Session state values are therefore typically set and retrieved as follows:

// Store a value sessionState["CurrentIndex"] = 5; // Retrieve a value if (sessionState.ContainsKey("CurrentIndex"))   index = (int)sessionState["CurrentIndex"];

Because this data must be persisted somewhere, the only requirement for the values is that they are serializable. The Dictionary could be persisted as follows, using the best practice of writing it into a local file ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.