简体   繁体   English

使用c#如何打印从解析文件中随机选择的行的行号

[英]using c# how to Print Line number of randomly selected line from parsed file

this is a snippet of my program that catches an incomplete line in the file, however I need it to tell me the line number that it pulled so I can do error handling better. 这是我的程序片段,在文件中捕获一个不完整的行,但我需要它告诉我它拉的行号,这样我可以更好地进行错误处理。

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;
        }
var lineNumber = Item.ran.Next(testLines.Length);
var randomTestLine = testLines[lineNumber];

... ...

ItemGenerated.Text = ( lineNumber + "Incomplete Item Entry\n" + randomTestLine);

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM