当我向你展示代码时
private static void Main(string[] args)
{
string[] strArray = new string[n];
int i = 0;
foreach (example)
{
if (condition 1)
{
strArray[i] = output;
}
if (condition 2)
{
strArray[i] = output;
}
if (condition 3)
{
strArray[i] = output;
}
i = i + 1;
}
}
进入.net fiddle,我得到:
Compilation error (line 1, col 16): Expected class, delegate, enum, interface, or struct
Compilation error (line 1, col 33): Identifier expected
Compilation error (line 1, col 35): Expected class, delegate, enum, interface, or struct
Compilation error (line 3, col 12): Identifier expected
Compilation error (line 3, col 14): Expected class, delegate, enum, interface, or struct
Compilation error (line 3, col 29): Expected class, delegate, enum, interface, or struct
Compilation error (line 3, col 38): Expected class, delegate, enum, interface, or struct
Compilation error (line 10, col 25): Expected class, delegate, enum, interface, or struct
Compilation error (line 11, col 9): Type or namespace definition, or end-of-file expected
用它包围它
public class MyClass
{
// your code
}
留给我
Compilation error (line 8, col 21): Identifier expected
Compilation error (line 8, col 22): ) expected
Compilation error (line 10, col 23): ) expected
Compilation error (line 10, col 24): ; expected
Compilation error (line 10, col 24): Invalid expression term ')'
Compilation error (line 10, col 25): ; expected
Compilation error (line 14, col 23): ) expected
Compilation error (line 14, col 24): ; expected
Compilation error (line 14, col 24): Invalid expression term ')'
Compilation error (line 14, col 25): ; expected
Compilation error (line 18, col 23): ) expected
Compilation error (line 18, col 24): ; expected
Compilation error (line 18, col 24): Invalid expression term ')'
Compilation error (line 18, col 25): ; expected
修复缺失n
和foreach
to
string[] strArray = new string[10];
int i = 0;
var data = new [] {"1","2","3","4"};
foreach (var example in data)
{
// your inner code
}
留给我
Compilation error (line 11, col 23): ) expected
Compilation error (line 11, col 24): ; expected
Compilation error (line 11, col 24): Invalid expression term ')'
Compilation error (line 11, col 25): ; expected
Compilation error (line 15, col 23): ) expected
Compilation error (line 15, col 24): ; expected
Compilation error (line 15, col 24): Invalid expression term ')'
Compilation error (line 15, col 25): ; expected
Compilation error (line 19, col 23): ) expected
Compilation error (line 19, col 24): ; expected
Compilation error (line 19, col 24): Invalid expression term ')'
Compilation error (line 19, col 25): ; expected
修复内在条件
if (i==1)
{
strArray[i] = "There is";
}
if (i==2)
{
strArray[i] = "is no";
}
if (i==3)
{
strArray[i] = "no spoon.";
}
i = i + 1;
导致缺少公共静态 Main,修复导致
public class MyClass
{
public static void Main(string[] args)
{
string[] strArray = new string[10];
int i = 0;
var data = new[]{"1", "2", "3", "4"};
foreach (var example in data)
{
if (i == 1)
{
strArray[i] = "There is";
}
if (i == 2)
{
strArray[i] = "is no";
}
if (i == 3)
{
strArray[i] = "no spoon.";
}
i = i + 1;
}
}
}
一个运行没有错误的程序。
在此旅程的任何地方都没有弹出错误消息。