Here is an example of what I want to do:
MessageBox.Show("Error line number "+CurrentLineNumber);
Current line number will be the line number in the source code of this piece of code.
How can I do that?
Here is an example of what I want to do:
MessageBox.Show("Error line number "+CurrentLineNumber);
Current line number will be the line number in the source code of this piece of code.
How can I do that?
In .NET 4.5 you can get the line number by creating the function:
Then each time you call
LineNumber()
you will have the current line. This has the advantage over any solution using the StackTrace that it should work in both debug and release.So taking the original request of what is required, it would become:
This is building on the excellent answer by Marc Gravell.