当前第2页 返回上一页
1 2 3 4 5 6 7 8 | HttpContext.Current.Application.Add( "key1" , "value1" );
HttpContext.Current.Application.Add( "key2" , "value2" );
HttpContext.Current.Application.Add( "KEY2" , "value3" );
int count = HttpContext.Current.Application.Count;
string [] keys = return HttpContext.Current.Application.AllKeys;
string s = ( string )HttpContext.Current.Application.Get( "key2" );
string s2 = ( string )HttpContext.Current.Application.Get(2);
|
如上代码,结果我们在备注中列出了。可以看出 Application 遇到键值相同,它既不报错,也不覆盖之前的,而是同时存在。用键值名称去取值时,取到的是同名中第一个对应的值。如果非要取后面的,就用 index。
如果我们要遇相同 name,就覆盖,可用下面的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | HttpContext.Current.Application.Add( "key1" , "value1" );
string name = "key2" ;
object obj = HttpContext.Current.Application.Get(name);
if (obj == null )
{
HttpContext.Current.Application.Add(name, "value2" );
}
else
{
HttpContext.Current.Application[name] = "value3" ;
}
return ( string )HttpContext.Current.Application[name];
|
上面代码中,直接修改 obj 是行不通的,但是遇到对象的话,如下代码是行得通的。说明:这是 C# 值引用、地址引用的知识点,与 Application 无关。
以上就是ASP.NET C#中Application的用法教程的详细内容!
返回前面的内容
相关阅读 >>
分享asp.net学习笔记(1)--webpages razor
.net core配置与自动更新的实现方法_实用技巧
asp.net core 应用程序发布命令实例
详解《asp.net》数据绑定―datalist
基于calendar实现blog日历的实例详解
《asp.net》数据的绑定―repeater图文详解
asp.net core应用程序在linux上部署的图文详解
使用c#操作windowad之添加对象到用户组
详细了解在.net core 上运行的wordpress
.net winform实现在listview中添加progressbar的方法
更多相关阅读请进入《.net》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » ASP.NET C#中Application的用法教程