Skip to main content
 首页 » 编程设计

c#之PHP $_GET ['something' ] 在 C# 中等效

2024年02月06日10wayfarer

我是 C# 的新手,但我在 PHP 工作,我需要一些与 C# 等效的 PHP 代码的帮助,这是我的代码

if(isset($_GET['something'] == 'today')) { 
 
    $test = $_GET['something']; 
} else { 
    $test = ''; 
} 

如何用 C# 编写?

请您参考如下方法:

Request.QueryString相当于PHP's $_GET在 C# 中。 QueryString 集合检索 HTTP 查询字符串中变量的值。

string test = Request.QueryString["something"]; 
        if (test == "today") 
        { 
            // we've got test logic 
        } 
        else 
        { 
           test = string.Empty; 
        }