拉风的咖菲猫
当我向你展示代码时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 小提琴,我得到:Compilation error (line 1, col 16): Expected class, delegate, enum, interface, or structCompilation error (line 1, col 33): Identifier expectedCompilation error (line 1, col 35): Expected class, delegate, enum, interface, or structCompilation error (line 3, col 12): Identifier expectedCompilation error (line 3, col 14): Expected class, delegate, enum, interface, or structCompilation error (line 3, col 29): Expected class, delegate, enum, interface, or structCompilation error (line 3, col 38): Expected class, delegate, enum, interface, or structCompilation error (line 10, col 25): Expected class, delegate, enum, interface, or structCompilation 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 expectedCompilation error (line 8, col 22): ) expectedCompilation error (line 10, col 23): ) expectedCompilation error (line 10, col 24): ; expectedCompilation error (line 10, col 24): Invalid expression term ')'Compilation error (line 10, col 25): ; expectedCompilation error (line 14, col 23): ) expectedCompilation error (line 14, col 24): ; expectedCompilation error (line 14, col 24): Invalid expression term ')'Compilation error (line 14, col 25): ; expectedCompilation error (line 18, col 23): ) expectedCompilation error (line 18, col 24): ; expectedCompilation error (line 18, col 24): Invalid expression term ')'Compilation error (line 18, col 25): ; expected修复丢失的n和foreach到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): ) expectedCompilation error (line 11, col 24): ; expectedCompilation error (line 11, col 24): Invalid expression term ')'Compilation error (line 11, col 25): ; expectedCompilation error (line 15, col 23): ) expectedCompilation error (line 15, col 24): ; expectedCompilation error (line 15, col 24): Invalid expression term ')'Compilation error (line 15, col 25): ; expectedCompilation error (line 19, col 23): ) expectedCompilation error (line 19, col 24): ; expectedCompilation 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; } }}一个运行没有错误的程序。在此过程中没有任何地方弹出您的错误消息。