为什么循环不起作用?为什么在局部变量“;y”;始终为int,s counter=1=int
本文关键字:int 为什么 counter 不起作用 循环 局部变量 | 更新日期: 2023-09-27 18:28:00
作为我所在大学的必修课,他们要求我们使用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
}