2 dimension arrays

G

Guest

Hi,

I have an array of 50 rows and 2 columns that I want to make available to a
user. As he goes thru the system, he will be updating and editing the array.
This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or is it
possible to put it as a session variable?

TIA. Cheers.
Andrew.
 
H

Hans Kesting

Andrew said:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static member of some class)
is the same for *all* users of your site (the single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have to
user Session. (other options: client side using ViewState or hidden inputs
or in a database under a user-specific key)


Hans Kesting
 
G

Guest

Thanks for your reply.
How do I declare an array as a session variable ?
I tried:

int [] marked = new int [50];
Session["marked[0] "] = 2;

I got a syntax error.

Hans Kesting said:
Andrew said:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static member of some class)
is the same for *all* users of your site (the single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have to
user Session. (other options: client side using ViewState or hidden inputs
or in a database under a user-specific key)


Hans Kesting
 
H

Hans Kesting

Andrew said:
Thanks for your reply.
How do I declare an array as a session variable ?
I tried:

int [] marked = new int [50];
Session["marked[0] "] = 2;

I got a syntax error.

untested code:

--------------
string[,] marked = (string[,])Session["marked"];

if (marked == null)
{
// nothing yet in session, so create it
marked = new string[50][2];
Session["marked"] = marked;
}

// use it
marked[12, 1] = "test";
-------------

Note: as you have a *reference* to this array, there is really only one array
so a change to 'marked' will "also update" the array "stored in the Session"
(to phrase it loosely). No need to "put the changed array back in the Session".

Hans Kesting

Hans Kesting said:
Andrew said:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static
member of some class) is the same for *all* users of your site (the
single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have
to
user Session. (other options: client side using ViewState or hidden
inputs
or in a database under a user-specific key)


Hans Kesting
 
G

Guest

Thanks a lot.

Hans Kesting said:
Andrew said:
Thanks for your reply.
How do I declare an array as a session variable ?
I tried:

int [] marked = new int [50];
Session["marked[0] "] = 2;

I got a syntax error.

untested code:

--------------
string[,] marked = (string[,])Session["marked"];

if (marked == null)
{
// nothing yet in session, so create it
marked = new string[50][2];
Session["marked"] = marked;
}

// use it
marked[12, 1] = "test";
-------------

Note: as you have a *reference* to this array, there is really only one array
so a change to 'marked' will "also update" the array "stored in the Session"
(to phrase it loosely). No need to "put the changed array back in the Session".

Hans Kesting

Hans Kesting said:
Andrew wrote:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static
member of some class) is the same for *all* users of your site (the
single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have
to
user Session. (other options: client side using ViewState or hidden
inputs
or in a database under a user-specific key)


Hans Kesting
 
J

Juan T. Llibre

re:
How do I declare an array as a session variable ?

That is a FAQ. The answer is at :
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=63





Andrew said:
Thanks for your reply.
How do I declare an array as a session variable ?
I tried:

int [] marked = new int [50];
Session["marked[0] "] = 2;

I got a syntax error.

Hans Kesting said:
Andrew said:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static member of some class)
is the same for *all* users of your site (the single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have to
user Session. (other options: client side using ViewState or hidden inputs
or in a database under a user-specific key)


Hans Kesting
 
G

Guest

Thanks

Juan T. Llibre said:
re:
How do I declare an array as a session variable ?

That is a FAQ. The answer is at :
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=63





Andrew said:
Thanks for your reply.
How do I declare an array as a session variable ?
I tried:

int [] marked = new int [50];
Session["marked[0] "] = 2;

I got a syntax error.

Hans Kesting said:
Andrew wrote:
Hi,

I have an array of 50 rows and 2 columns that I want to make
available to a user. As he goes thru the system, he will be updating
and editing the array. This is unique to each user in the session.

eg. public string[,] marked = new String[50][2].

How do you suggest I do it ? Do I declare it as global variable, or
is it possible to put it as a session variable?

TIA. Cheers.
Andrew.

You will *need* to put in in Session: a "global variable" (static member of some class)
is the same for *all* users of your site (the single webapp serves multiple users).
If you want to retain user-specific data in server-memory, you have to
user Session. (other options: client side using ViewState or hidden inputs
or in a database under a user-specific key)


Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top