[英]The name userInput does not exist in the current context. Why?
I have this at the moment:我现在有这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
static void Main(string[] args)
{
Console.WriteLine("Which teams have played? right vs inbetween the two teams");
Match m = Regex.Match("^(?<team1>\.+) vs (?<team2>\.+)$", userInput);
if (m.Success)
{
string team1 = m.Groups["team1"].Value;
string team2 = m.Groups["team2"].Value;
}
Console.WriteLine("What is the score? ");
Match m = Regex.Match("^(?<score1>\.+)/(?<score2>\.+)$", userInput);
if (m.Success)
{
int score1 = m.Groups ["score1"].Value;
int score2 = m.Groups ["score2"].Value;
}
I get an error on the dot saying:我在点上得到一个错误说:
"Unrecognized escape sequence
^(?<team1>\.+)
"“无法识别的转义序列
^(?<team1>\.+)
”
It also does tells me this on the score1
and score2
lines:它还在
score1
和score2
行上告诉我这一点:
"The type or namespace name
Match
could not be found (are you missing a using directive or an essembly reference?)"“找不到类型或命名空间名称
Match
(您是否缺少 using 指令或 essembly 引用?)”
And:和:
"The name `Regex´ does not excist in the current context."
“‘Regex’这个名字在当前上下文中并不存在。”
What I am trying to do is to read two answers from one line and read it as two answers.我要做的是从一行中读取两个答案并将其作为两个答案阅读。
For example: BlueTeam vs RedTeam.例如:蓝队与红队。
Also want to do the same thing for the score.也想为分数做同样的事情。 For example: 1/1 I know the slash is a bit weird but I just did it out of pure laziness to think of something else.
例如:1/1 我知道斜线有点奇怪,但我只是出于懒惰去想别的东西。
And later on the path I want to assign this into a xy-table.稍后在路径上,我想将其分配到 xy 表中。 Like so: http://pastebin.com/ahgP04bU
像这样: http://pastebin.com/ahgP04bU
By putting your variables in {... }
, you're creating a separate block scope with those variables.通过将变量放入
{... }
,您将使用这些变量创建一个单独的块 scope。 They don't exist outside that scope.它们不存在于 scope 之外。
Don't do that.不要那样做。
The Regex
class is in the System.Text.RegularExpressions
namespace;正则
Regex
class 位于System.Text.RegularExpressions
命名空间中; you need to include that namespace using the using
statement.您需要使用
using
语句包含该命名空间。
You also have to include您还必须包括
using System.Text.RegularExpressions
in order to use regular expressions without fully qualifying.为了使用没有完全限定的正则表达式。
Edit: There is a lot that would also improve your code.编辑:还有很多可以改进你的代码。 When you define your variables inside the
if
blocks, those variables are then locally scoped to the if block and are garbage collected as soon as the if block finishes.当您在
if
块中定义变量时,这些变量将在本地范围内限定为 if 块,并在 if 块完成后立即进行垃圾收集。
Also, I don't see where userInput is defined anywhere in your code.另外,我看不到代码中任何地方的 userInput 定义。
{ }
) are currently missing.{ }
)。using System.Text.RegularExpressions
at the top of the file with the others.using System.Text.RegularExpressions
。userInput
doesn't exist, you need to declare it: var userInput = string.Empty;
userInput
不存在,需要声明: var userInput = string.Empty;
\
), you can use @
: @"\myString"
\
),您可以使用@
: @"\myString"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.