朋友您好,我在上课时遇到问题.我需要检查页面加载中的新会话.所以请告诉我解决方法 [英] Hello friends i have a problem in session . I need to check for a new session in page load . so please tell me solution

查看:56
本文介绍了朋友您好,我在上课时遇到问题.我需要检查页面加载中的新会话.所以请告诉我解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#中下面三个代码行之间有什么区别?
他们是同一个

1.如果(Session ["DETAILS"] == null)


2. if(session ["Details"] ==")


3. if(Session ["DETAILS"].ToString()=="NEW")

What is the difference between three below code lines in c#?
Are they same

1. if (Session["DETAILS"] == null)


2. if(session["Details"] == "")


3. if(Session["DETAILS"].ToString() == "NEW")

推荐答案

嘿,

用您的编号指代要点:
1.检查Session是否包含带有键"Details"的数据
2.这是不正确的.会话自动将您的值装箱. IE.在进行任何类型的比较之前,您必须转换为所需的类型.返回的默认类型为object.因此,我认为该行甚至都不会编译,因为您无法将objectstring
进行比较 3.这将调用存储在会话键详细信息"中的任何对象的.ToString().返回的结果在``ToString()''方法的实现上有所不同.重要的是要注意,如果Session不包含键"Details"的值,它将引发异常.

希望能对您有所帮助,问候
Hey there,

Referring to the points by your numbering:
1. Checks whether the Session contains data with the key ''Details''
2. This is incorrect. Session automatically boxes your values. I.e. you have to cast to the type you want prior doing any kind of comparison. The default type returned is object. So I believe that line would not even compile, since you cannot compare an object to a string
3. This calls the .ToString() of any object stored on the Session key ''Details''. The result returned differs on the implementation of the ''ToString()'' method. It''s important to note that, it will throw an exception, if the Session does not contain a value for the key ''Details''

Hope this helps, Regards


if(Session["Name"] == null)
                if(Session["Name"]=="")
                    if(Session["Name"].ToString()=="")



1.检查是否存在带有名称"的会话(是否已连接)
2.检查带有名称"的会话是否有数据
3.与2.相同.大多数情况下,会话中的数据在处理之前都会转换为字符串.
只需使用此代码段并尝试调试,您​​就可以很好地理解.



1.checks whether session with "Name" exists or not(crated or not)
2. checks if session with "Name" has data or not
3. Same as 2. Most often data in session is converted to string before dealing with it.
just use this snippet and try debugging, u can understand well.


这篇关于朋友您好,我在上课时遇到问题.我需要检查页面加载中的新会话.所以请告诉我解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆