簡體   English   中英

使用c#如何打印從解析文件中隨機選擇的行的行號

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

這是我的程序片段,在文件中捕獲一個不完整的行,但我需要它告訴我它拉的行號,這樣我可以更好地進行錯誤處理。

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