作为我大学的一项强制性任务,要求我们使用 c# 我正在尝试构建一个包含 3 个阶段的编译器,这是我一生中第一次用 c# 编写,也是第一次在这样的大型项目中工作
1)解析器
2)错误检查器
3)内存
为什么循环不起作用?为什么在局部变量“y”总是 int 而 s counter = 1 = “identifier”
foreach (string word in words)
{
string y = "";
string z = "";
string m = "";
string er = "";
string numb = "";
string vari = "";
List<string> s = new List<string>();
if (word == "/")
{
y += word;
y += "= operand\n";
s.Add(word);
}
else if (word == "+")
{
y += word;
y += "= operand\n";
s.Add(word);
}
else if (word == "*")
{
y += word;
y += "= operand\n";
s.Add(word);
最佳答案
用 for 替换你的 foreach 循环怎么样?
http://www.david-amador.com/2009/12/csharp-foreach-vs-for-loop/
您的循环将如下所示:
for (int index = 0; index < words.Count; index++)
{
var word = words[index];
//doStuff
}
关于c# - 为什么循环不起作用?为什么在局部变量 "y"总是 int 而 s counter = 1 = int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34450425/