Re: 2 dimension arrays



Andrew wrote:
> 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" wrote:
>
>> 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


.



Relevant Pages

  • Re: 2 dimension arrays
    ... Andrew wrote: ... > and editing the array. ... This is unique to each user in the session. ... If you want to retain user-specific data in server-memory, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: help with array within another array
    ... array @SESSION. ... I am trying to declare two associative array ... (%nodeowner and %nodeseverity) ...
    (perl.beginners)
  • RE: Session variables and reference
    ... Session variable that is an array of a class I created: ... public cut//copy constructor ... Kmax = myCut.Kmax; ... I realized that when I set my temporary array to equal the session array, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: help with array within another array
    ... you could make a hash with reference to hash values: ... it seems like you might want to consider using the node identifier as the first key in %SESSION, and make the value a reference to hash keyed by the owner and severity: ... I am trying to declare two associative array ...
    (perl.beginners)
  • Re: [PHP] SESSION problem
    ... But, if you came from a background that predated associate arrays, then using numeric indexes would seem more natural. ... looked into the session extension in that level of detail, but I doubt such a limitation would exist if there was not a very good reason for it. ... Given that I can't see into the future, even if I currently only have one set of data to store in the session I wouldn't just chuck the bits of paper from the file into the filing cabinet. ... The root level of the session array should contain descriptive keys, and I've never been in a situation where 5318008 is descriptive and gives context to the data unless you turn it upside down! ...
    (php.general)