【发布时间】:2016-09-08 03:33:48
【问题描述】:
查看链接:
http://i.imgur.com/gFcamd8.png
注意底部的 Autos 窗口显示 toParse = ""。但是 toParse != "" 无论如何都会评估为 true,从而导致应用程序崩溃。
这是完整的方法:
public void parseString(string toParse)
{
while (toParse != "")
{
string nextLine = readLine(ref toParse);
if (nextLine.IndexOf("//") == 0)
{
comments.Add(nextLine);
continue;
}
if (nextLine.IndexOf(".") == 0)
{
string[] declarationParts = nextLine.Split(' ');
string declarationString = declarationParts[0].Substring(1, declarationParts[0].Length - 1);
declarationString = char.ToUpper(declarationString[0]) + declarationString.Substring(1);
DirectiveEnum type = (DirectiveEnum)Enum.Parse(typeof(DirectiveEnum), declarationString);
string[] attributes = declarationParts.Skip(1).ToArray();
MSILNode newNode = new MSILNode(type);
newNode.addAttributes(attributes);
toParse = toParse.Trim();
if (toParse != "")
{
while (toParse[0] != '{' && toParse[0] != '.' && toParse.IndexOf("//") != 0)
{
nextLine = readLine(ref toParse);
attributes = nextLine.Split(' ');
newNode.addAttributes(attributes);
}
if (toParse[0] == '{')
{
readLine(ref toParse);
string inside = separate(ref toParse, "}");
newNode.parseString(inside);
}
}
subNodes.Add(newNode);
continue;
}
Console.WriteLine(nextLine);
}
}
【问题讨论】:
-
toParse 的值是多少?
-
toParse的长度是多少? -
见操作:toParse = ""
-
长度为 0。如果我使用 toParse.Length != 0,也会出现同样的问题。
标签: c# if-statement logical-operators