0

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;
        }
2
  • What language is this? Please edit the question to include the appropriate language tag(s). Commented Feb 19, 2014 at 21:28
  • I totally spaced out and forgot that, there fixed. Commented Feb 19, 2014 at 21:46

1 Answer 1

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

...

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

?

Sign up to request clarification or add additional context in comments.

1 Comment

that worked perfectly thank you. I needed to add ItemGenerated.Text = ( (lineNumber + 1) + "Incomplete Item Entry\n" + randomTestLine); so the count would match properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.