asp.net - Passing list<string> to a function -


i have session variable create dynamically, lets instance have following session variables

session["area1"] session["area2"] session["area3"] session["area4"] 

and in each of sessions have list in there

then have in order name , use in code

string areaname = "area" + session["area"]; 

session["area"] session variable increases self based on how many times button clicked

now if try pass areaname function requiring list parameter doesn't let me it, though value in session variable list

i using "areaname" able name of session

how can use in order pass function requiring list type?

by calling following:

string areaname = "area" + session["area"]; 

you saying, take string "area", , append variable session (which object default), call it's tostring() method. end result here, string, not list. (and not meaningful 1 @ that).

all need take session value, , cast type know is.

method((list<string>)session["area"]) 

or

method(session["area"] list<string>) 

the reason can't pass in session["area"] without first casting, because session returns variable object. sure, may list in memory, system treats same other object (look polymorphism more info), not list expects. thus, compile time error, unless cast correct type.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -