C#打开每个文本文件并阅读所有文本问题

3 c#

{
        DirectoryInfo dinfo = new DirectoryInfo(@"C:\Documents and Settings\g\Desktop\123");
        FileInfo[] Files = dinfo.GetFiles("*.txt");
        foreach (FileInfo filex in Files)
        {
            string contents = File.ReadAllText(filex);
            string sharename = Regex.Match(contents, @"\Share+(\S*)(.)(.*)(.)").Groups[2].Value;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我只是想能够打开这个目录中的每个文本文件,阅读全部,然后拉出我列出的正则表达式,有了这个代码,有人可以指出我的脑屁在哪里?

'System.IO.File.FileInfo'到'string'的最佳重载方法匹配有一些无效参数参数'1'无法将frm System.IO.FileInfo转换为字符串

Dar*_*rov 23

ReadAllText方法期望字符串类型,而不是一个文件名参数的FileInfo:

string contents = File.ReadAllText(filex.FullName);
Run Code Online (Sandbox Code Playgroud)