第一次运行时给Cache赋于值类型时,第二次运行时去掉赋值这段程序,Cache的数据还是能输出
相反如果是引用类型二次运行时,报引用类型数据是空的,这是什么??????第一次运行时加
<script language="C#" runat="server"> public class Data
{
public string STR;
public Data(string s)
{
STR = s;
}
}</script>
第一次加 结束<%
//赋值
for(int i=0; i< 10; i++)
{
//值类型时
Cache[i.ToString()] = 1;
//引用类型时
Cache[i.ToString()] = new Data(i.ToString());
}
IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while(CacheEnum.MoveNext())
{
DictionaryEntry cacheItem = (DictionaryEntry)CacheEnum.Current;
//引用类型时
Data data = cacheItem.Value as Data;
Response.Write("Key:" + cacheItem.Key + "Data:" + cacheItem.Value + "<br>"); //值类型时
Response.Write("Key:" + cacheItem.Key + "Data:" + data.STR + "<br>");
}
%>
相反如果是引用类型二次运行时,报引用类型数据是空的,这是什么??????第一次运行时加
<script language="C#" runat="server"> public class Data
{
public string STR;
public Data(string s)
{
STR = s;
}
}</script>
第一次加 结束<%
//赋值
for(int i=0; i< 10; i++)
{
//值类型时
Cache[i.ToString()] = 1;
//引用类型时
Cache[i.ToString()] = new Data(i.ToString());
}
IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while(CacheEnum.MoveNext())
{
DictionaryEntry cacheItem = (DictionaryEntry)CacheEnum.Current;
//引用类型时
Data data = cacheItem.Value as Data;
Response.Write("Key:" + cacheItem.Key + "Data:" + cacheItem.Value + "<br>"); //值类型时
Response.Write("Key:" + cacheItem.Key + "Data:" + data.STR + "<br>");
}
%>
解决方案 »
- 用ASP.NET做个博客需要用到几张表,具体是哪几张?需要注意什么?
- 如何用ASP.NET实现图片大小减少,但效果损失不太大?
- 读取数据库表格字段 生成 CheckBox,非常急 请各位高手指点 在线等,谢谢啊!分数不够可以再加!请各位帮帮忙!
- 哪有sqlserver 2005 professional 中文正式版下载啊
- 请问怎么将Color转换成#000000这样的颜色代码或者red这样的名字
- 请问如何配置web.config文件?
- 为什么我在aspx的后台编码中使用treeview控件申明不了节点?
- 求助:如何比较两个sql server数据库是否一样。
- 一些e书网址,大家共享
- xml中如何判断一个节点node1中有没有属性arr1?
- 如何能把我们OA中的网页设成桌面?
- 如何将十六进制的字符串转换为二进制的字符串?
Cache boovoo_cache;
HttpContext context = HttpContext.Current;
if(context != null)
{
boovoo_cache = context.Cache;
}
else
{
boovoo_cache = HttpRuntime.Cache;
}
public static void Clear()
{
IDictionaryEnumerator CacheEnum = boovoo_cache.GetEnumerator();
while(CacheEnum.MoveNext())
{
boovoo_cache.Remove(CacheEnum.Key.ToString());
} }