One approach will be anonymous:
var ids = dt.AsEnumerable().Select(x => new
{
Id = (int)x["Id"],
Level = (int)x["level"]
}).ToList();
This will give you List<>this anonymous type, so now you can do something like this:
var level = ids[0].Level
UPDATE: if you need to save them in Sessionto save, I would recommend creating a real type ( class), call it Foofor this example. This will change the code to:
var ids = dt.AsEnumerable().Select(x => new Foo
{
Id = (int)x["Id"],
Level = (int)x["level"]
}).ToList();
Then, when you need to infer them from Session:
var ids = (List<Foo>)Session["ids"];
source
share