Question

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;
        }
Was it helpful?

Solution

var lineNumber = Item.ran.Next(testLines.Length);
var randomTestLine = testLines[lineNumber];

...

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

?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top