C # return to type var?

I am working on an ASP.NET application using LinqToSQL. When the page loads, I run a query and stores the result in a variable ... var tasks = query expression. Then I save this in the session variable Session["Tasks"] = tasks...

Is it possible to return this session object to the initial state of var, so I can run methods like Count(), Reverse()etc.?

thanks

+5
source share
3 answers

var is just brief for type inference ... the real question here is: what is the base type?

(.. {...} List<> ), ( ). ; ...

, , IQueryable<T>, - - ( ) .ToList()/.ToArray() ..

: ; ( ), ; ( ..) , . ; .

():

var tasksQuery = from task in ctx.Tasks
             where task.IsActive
             orderby task.Created
             select task; // this is IQueryable<Task>

Session["Tasts"] = tasksQuery.ToArray(); // this is Task[]
...
var tasks = (Task[]) Session["Tasts"]; // this is Task[]
+15

var , #, .

string s = "Hello world!";

var s = "Hello world!";

s. ,

using System.Linq

- , , .

+4

var "" , , . , " var"

0

All Articles