how to print out line number during application run in VB.net

后端 未结 3 409
死守一世寂寞
死守一世寂寞 2021-01-24 22:32

I would like to print out my debug message with line number in VB.net application. I did like this,

Dim st As StackTrace
Dim sf As StackFramee
st = New StackTrac         


        
3条回答
  •  生来不讨喜
    2021-01-24 23:19

    After reading the several answers I came for me to the following solution as equivalent to the C++ macro LINE

    (New StackTrace(New StackFrame(True))).GetFrame(0).GetFileLineNumber())
    

    which can be used for example as:

    Console.WriteLine(String.Format("Executed on line# {0}", (New StackTrace(New StackFrame(True))).GetFrame(0).GetFileLineNumber()))
    

提交回复
热议问题