测试会话变量是否为空或空的空间 [英] Testing a session variable for null or empty space

查看:53
本文介绍了测试会话变量是否为空或空的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前所拥有的是:

if ((string)Session["PlanID"] == null)
{
   string PlanID = Request.QueryString["PlanID"];
   Session["PlanID"] = PlanID;
}

我需要的是这样的东西:

What I need is something like this:

if ((string)Session["PlanID"] == null) or if ((string)Session["PlanID"] == "")
{
   string PlanID = Request.QueryString["PlanID"];
   Session["PlanID"] = PlanID;
}

我该怎么做?

推荐答案

您可以从字符串中使用IsNullOrEmpty.

You can use IsNullOrEmpty from string.

if (string.IsNullOrEmpty((string)Session["PlanID"])) {
   string PlanID = Request.QueryString["PlanID"];
   Session["PlanID"] = PlanID;
}

这篇关于测试会话变量是否为空或空的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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