这是我程序的一个片段,它在文件中捕获一条不完整的行,但我需要它告诉我它拉出的行号,这样我就可以更好地处理错误。
var testLines = File.ReadAllLines(openFileDialog1.FileName);
Item.ran = new Random(Guid.NewGuid().GetHashCode());
var randomTestLine = testLines[Item.ran.Next(testLines.Length)];
if (randomTestLine.StartsWith("*"))
{
pick++;
count = pick.ToString();
Picks.Font = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
Picks.Text = count;
ItemGenerated.Text = ( !!something needs to go here!! + "Incomplete Item Entry\n" + randomTestLine);
return false;
}
答案 0 :(得分:2)
var lineNumber = Item.ran.Next(testLines.Length);
var randomTestLine = testLines[lineNumber];
...
ItemGenerated.Text = ( lineNumber + "Incomplete Item Entry\n" + randomTestLine);