【发布时间】:2016-12-22 19:29:17
【问题描述】:
return(match) 让我头疼!当我将其更改为 Console.WriteLine(match) 时,它给了我期望的回报,但是当我尝试使用 return(match) 时,它给了我一个错误。我只是不知道要在这里改变什么,所以任何建议都将不胜感激!
问候,詹姆斯
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ReadTextFile
{
class Program
{
static void Main(string[] args)
{
List<string> fileLines = new List<string>();
using (var reader = new StreamReader("test.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
fileLines.Add(line);
string pattern = @"(\w+)@(\w+).([a-z]+)";
Match match = Regex.Match((line), pattern);
if (match.Success)
{
return(match);
}
}
}
【问题讨论】:
-
Main是一个void函数。你要回到谁身边? -
您不能在
void方法中使用return。你想用这个值做什么? -
看起来你想退出你的while循环,只需使用
break;语句 -
你要输出匹配的值吗?为应用设置退出代码?
标签: c#