What is the best way to determine a session variable is null or empty in C#?

后端 未结 12 2675
野趣味
野趣味 2020-11-29 15:33

What is the best way to check for the existence of a session variable in ASP.NET C#?

I like to use String.IsNullOrEmpty() works for strings and wonder

12条回答
  •  被撕碎了的回忆
    2020-11-29 16:19

    That is pretty much how you do it. However, there is a shorter syntax you can use.

    sSession = (string)Session["variable"] ?? "set this";
    

    This is saying if the session variables is null, set sSession to "set this"

提交回复
热议问题