Archive for July, 2010

Interesting message from Mono C# compiler

Saturday, July 3rd, 2010
List<Position> result;
// insert the questions into a structure to make them easy to search
while ((line = data.ReadLine ()) != null) {
//Console.WriteLine (”{0}”, line);
string[] words = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
wordPosition = 0;
foreach (string word in words) {
if ((result = noSig.Find(word)).Count != 0)
significant = true;
else
significant = false;
//Console.WriteLine (”{0}: {1} {2} ({3}))”, lineCount, wordPosition, word, significant);

Position p

= new Position (lineCount, wordPosition++, significant);

wordTree.Add (word, p);
}
lineCount++;
}
First off, hard to believe it’s been so long since I posted here.
I ran across an interesting little problem the latest C# compiler for mono has in analyzing this bit of code:
 List<Position> result;
 // insert the questions into a structure to make them easy to search
 while ((line = data.ReadLine ()) != null) {
   string[] words = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
   wordPosition = 0;
   foreach (string word in words) {
     if ((result = noSig.Find(word)).Count != 0)
       significant = true;
     else
       significant = false;
     Position p = new Position (lineCount, wordPosition++, significant);
     wordTree.Add (word, p);
   }
   lineCount++;
 }
This code gives me the warning:
The variable ‘result’ is assigned but never used (CS0219)
The code shown in red is obviously using the variable. A bit indirectly, perhaps.
Since I had been editing code and renaming variables I thought that I had just missed one, so I deleted it. Which caused the next problem, that the variable result was not defined :)
Not a big deal, I just found it amusing.