> I am looking for C# code to store and retrieve a 2 dimensional array in the
> cache. I have seen code in this forum for caching arrays but ti does not
> work. I'd be immensely grateful if anyone has an example.
Standard question #1:
What do you mean by "not working"?
A two dimensional array is an object, just like a one dimensional array.
It isn't harder to cache a two dimensional array just because it has
more dimensions.
tx_tom - 02 May 2006 02:44 GMT
Hi Goran:
This is the code I tried to use. It is 2 different technigues to accomplish
the same thing but neither worked.
Thanks in advance
// Get the array from the cache:
MyType[] array = (MyType[]) Cache["key"];
private MyType[] GetArray()
{
// Try to get the return value.
MyType[] retVal = (MyType[]) Cache["key"];
// If the item does not exist, then
// add it here.
if (retVal == null)
{
// Add the array to the cache here.
retVal = <create array here>;
// Add the item to the cache.
Cache["key"] = retVal;
}
// Return the array.
return retVal;
}
>> I am looking for C# code to store and retrieve a 2 dimensional array in the
>> cache. I have seen code in this forum for caching arrays but ti does not
[quoted text clipped - 6 lines]
>It isn't harder to cache a two dimensional array just because it has
>more dimensions.
> I am looking for C# code to store and retrieve a 2 dimensional array in the
> cache. I have seen code in this forum for caching arrays but ti does not
> work. I'd be immensely grateful if anyone has an example.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
tx_tom - 02 May 2006 02:48 GMT
Sure Jon:
This is the code I tried to use. It is 2 different technigues to accomplish
the same thing but neither worked.
Thanks in advance
// Get the array from the cache:
MyType[] array = (MyType[]) Cache["key"];
private MyType[] GetArray()
{
// Try to get the return value.
MyType[] retVal = (MyType[]) Cache["key"];
// If the item does not exist, then
// add it here.
if (retVal == null)
{
// Add the array to the cache here.
retVal = <create array here>;
// Add the item to the cache.
Cache["key"] = retVal;
}
// Return the array.
return retVal;
}
This is how I placed the array in the Cache. I think this works.
Cache["shArray"] = shArray;
>> I am looking for C# code to store and retrieve a 2 dimensional array in the
>> cache. I have seen code in this forum for caching arrays but ti does not
[quoted text clipped - 5 lines]
>See http://www.pobox.com/~skeet/csharp/complete.html for details of
>what I mean by that.
Göran Andersson - 02 May 2006 15:03 GMT
For a two dimensional array you just declare the array as having two
dimensions:
MyType[,] array = (MyType[,]) Cache["key"];
> Sure Jon:
>
[quoted text clipped - 38 lines]
>> See http://www.pobox.com/~skeet/csharp/complete.html for details of
>> what I mean by that.