CSDN大虾真多,我好喜欢这里呀。这不,我这又有问题要问了:
这里为什么要将int作个转换?难道Application对象只接收object类型的变量?
int count = 0;
object obj = count;
Application["counter"] = obj;完整代码如下:
public partial class counter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int count = 0;
if (Session["OnLine"].ToString() == "true")
{
Application.Lock();
count = (int)Application["counter"];
count = count + 1;
object obj = count;
Application["counter"] = obj; //将数据记录写入文件
string strFilePath = Server.MapPath("counter.txt");
StreamWriter SW = new StreamWriter(strFilePath, false);
SW.WriteLine(count);
SW.Close();
Session["count"] = count.ToString();
Application.UnLock();
Session["OnLine"] = "false";
}
else
{
count = Convert.ToInt32(Session["count"]);
}
string strCounter = count.ToString();
string imgName;
Response.Write("您是第");
for (int i = 0; i < strCounter.Length; i++)
{
imgName = strCounter.Substring(i, 1);
Response.Write(imgName);
}
Response.Write("位访问者");
}
}
}
这里为什么要将int作个转换?难道Application对象只接收object类型的变量?
int count = 0;
object obj = count;
Application["counter"] = obj;完整代码如下:
public partial class counter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int count = 0;
if (Session["OnLine"].ToString() == "true")
{
Application.Lock();
count = (int)Application["counter"];
count = count + 1;
object obj = count;
Application["counter"] = obj; //将数据记录写入文件
string strFilePath = Server.MapPath("counter.txt");
StreamWriter SW = new StreamWriter(strFilePath, false);
SW.WriteLine(count);
SW.Close();
Session["count"] = count.ToString();
Application.UnLock();
Session["OnLine"] = "false";
}
else
{
count = Convert.ToInt32(Session["count"]);
}
string strCounter = count.ToString();
string imgName;
Response.Write("您是第");
for (int i = 0; i < strCounter.Length; i++)
{
imgName = strCounter.Substring(i, 1);
Response.Write(imgName);
}
Response.Write("位访问者");
}
}
}
解决方案 »
- 关于<pages validateRequest="false" />-问题
- SOCKET网络编程中传送多个文件的问题
- datagridview 拖动列问题
- 打印功能。
- 请问有办法用程序获取windows所有帐户名吗?
- 重写DataGridViewComboBoxColumn控件 ,,大家来看看!!
- 关于这句(Hashtable)Session["bus"]怎么理解;
- 如何让 Label.Text 的字居中显示?
- datatable 转换成 datarow
- C#建立的项目,生成一个XX.csproj和xx.sln文件,有什么区别啊?
- DataList存储过程分页代码 最要带注释的 我是新手 谢谢
- 哪个帮我解决下这个问题,让SPAN是否显示在页面上,根据DATASET里面的值~
==
Application中放的是object对象的引用
count = (int)Application["counter"]; 看一下装箱和拆箱。