有没有一种基于.NET / C#isset()函数的?函数、NET、isset

2023-09-05 23:28:23 作者:降妞十巴掌

我要检查是否有对URI请求的参数。

I need to check if there is a param on the uri request.

所以,我需要检查,如果该参数设置。是否有.NET函数/ C#?

So I need to check if that param is set. Is there a function on .NET/C#?

推荐答案

这是未设置值为null或空:

An unset value will be null or empty:

value = Request["param"];
if (String.IsNullOrEmpty(value))
{
    // param is not set
}

如果该PARAM NAME是在查询字符串,但该值不是,这将是空的。如果名字不在查询字符串,其值将为空。例如,

If the param name is in the query string but the value is not, it will be empty. If the name is not in the query string, the value will be null. For example.

&param1=&param2=value 
// Request["param1"] is String.Empty
// Request["param3"] is null