|
 |
aspx thread: Foreaching Cache In C#
Message #1 by "Mark Phillips" <margia5@h...> on Sat, 12 May 2001 11:06:51
|
|
I am trying to loop thru the values that I have added to and ASP+ Web
Cache using C#. I was translating the Chapter 4 VB code in ASP+ Preview
to C#.
I am using:
foreach(object item in Cache)
{
DictionaryEntry dic =(DictionaryEntry)item;
string strName = dic.Key.ToString();
if(! strName.StartsWith("System."))
strContents += strName + " = " + Cache[strName] + "<br/>";
}
I have cast the item to a DictionaryEntry object and then utilized the
DictionaryEntry Key property. Have I added an extra step, missed
something, or is this as small as the code can get?
Thanks,
Mark
Thanks,
Mark
Message #2 by "Thomas Tomiczek" <t.tomiczek@t...> on Sat, 12 May 2001 13:02:13 +0200
|
|
Try this:
foreach(DictionaryEntry entry in Cache) {
string strName =3D entry.Key.ToString();
if(! strName.StartsWith("System."))
strContents +=3D strName + " =3D " + entry.Value + "<br/>";=09
}
See two changes:
(a) I can skip the last saving one line of code.
(b) I do NOT ask the cache again with the key string, simply because -
the entry that I have has the value property, thus I skip a lookup,
being faster.
Regards
Thomas Tomiczek
THONA Consulting Ltd.
-----Original Message-----
From: Mark Phillips [mailto:margia5@h...]
Sent: Samstag, 12. Mai 2001 13:07
To: ASP+
Subject: [aspx] Foreaching Cache In C#
I am trying to loop thru the values that I have added to and ASP+ Web
Cache using C#. I was translating the Chapter 4 VB code in ASP+ Preview
to C#.
I am using:
foreach(object item in Cache)
{
DictionaryEntry dic =3D(DictionaryEntry)item;
string strName =3D dic.Key.ToString();
if(! strName.StartsWith("System."))
strContents +=3D strName + " =3D " + Cache[strName] + "<br/>";=09
}
I have cast the item to a DictionaryEntry object and then utilized the
DictionaryEntry Key property. Have I added an extra step, missed
something, or is this as small as the code can get?
Thanks,
Mark
Thanks,
Mark
Message #3 by "Mark Phillips" <margia5@h...> on Sat, 12 May 2001 20:03:26
|
|
Thomas,
Thanks for the input. Going directly to the dictionary works well,
in getting the Key, but not for the Value. Seems like I have to go thru
the Cache. Requesting the value thru the dictionary
returns "System.Web.Caching.CacheEntry"
thanks for your input,
Mark
> Try this:
>
> foreach(DictionaryEntry entry in Cache) {
> string strName =3D entry.Key.ToString();
>
> if(! strName.StartsWith("System."))
> strContents +=3D strName + " =3D " + entry.Value
+ "<br/>";=09
> }
>
> See two changes:
> (a) I can skip the last saving one line of code.
> (b) I do NOT ask the cache again with the key string, simply because -
> the entry that I have has the value property, thus I skip a lookup,
> being faster.
>
> Regards
>
> Thomas Tomiczek
> THONA Consulting Ltd.
>
>
> -----Original Message-----
> From: Mark Phillips [mailto:margia5@h...]
> Sent: Samstag, 12. Mai 2001 13:07
> To: ASP+
> Subject: [aspx] Foreaching Cache In C#
>
> I am trying to loop thru the values that I have added to and ASP+ Web
> Cache using C#. I was translating the Chapter 4 VB code in ASP+ Preview
>
> to C#.
>
> I am using:
>
> foreach(object item in Cache)
> {
> DictionaryEntry dic =3D(DictionaryEntry)item;
> string strName =3D dic.Key.ToString();
>
> if(! strName.StartsWith("System."))
> strContents +=3D strName + " =3D " + Cache[strName] + "<br/>";=09
> }
>
> I have cast the item to a DictionaryEntry object and then utilized the
> DictionaryEntry Key property. Have I added an extra step, missed
> something, or is this as small as the code can get?
>
> Thanks,
> Mark
>
> Thanks,
> Mark
>
|
|
 |