Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我如何使函数Regex工作?_C#_Asp.net - Fatal编程技术网

C# 我如何使函数Regex工作?

C# 我如何使函数Regex工作?,c#,asp.net,C#,Asp.net,早上好, 我正在为我的intership做一个页面,我发现了这个函数,但它不起作用,有人能帮我吗? 先谢谢你 string _id = this.txtIdGrupo.Text; if (!Regex.IsMatch(_id, @"^\d+$")) return false; 结果表明: error CS0103: The name 'Regex' does not exist in the current context 这不是您显示的代码的问题 这是文

早上好, 我正在为我的intership做一个页面,我发现了这个函数,但它不起作用,有人能帮我吗? 先谢谢你

string _id = this.txtIdGrupo.Text;

if (!Regex.IsMatch(_id, @"^\d+$"))   
    return false;
结果表明:

error CS0103: The name 'Regex' does not exist in the current context

这不是您显示的代码的问题

这是文件顶部的名称空间问题

解决办法应该是

在行动中看到它:

请注意使用System.Text.RegularExpressions

使用诸如Resharper和类似的工具肯定会给你提示,并会改善你的日常生活

确保您拥有System.Text.RegularExpressions
是否已导入

当您对该错误代码进行web搜索时,您学到了什么?@adrianhh-您所说的web搜索是什么?使用System.Text.RegularExpressions?哦,好的,实际上我没有,谢谢你,没有问题,我会搜索那张通行证的,谢谢
using System;
using System.Text.RegularExpressions;
    
public class Test
{            
    public static void Main ()
    {
        var isNumeric1 = IsNumeric("1");
        Console.WriteLine(isNumeric1);

        var isNumeric2 = IsNumeric("HelloWorld");
        Console.WriteLine(isNumeric2);

        //call IsNumeric with the value of this.txtIdGrupo.Text like this
        //var isNumeric = IsNumeric(this.txtIdGrupo.Text);
    }

    private static bool IsNumeric(string str)
    {
        string id = str;

        if (!Regex.IsMatch(id, @"^\d+$"))   
            return false;

        return true;
    }
}