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

后端 未结 12 2681
野趣味
野趣味 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:05

    Are you using .NET 3.5? Create an IsNull extension method:

    public static bool IsNull(this object input)
    {
        input == null ? return true : return false;
    }
    
    public void Main()
    {
       object x = new object();
       if(x.IsNull)
       {
          //do your thing
       }
    }
    

提交回复
热议问题