C# get current line number in cs file

using System.Diagnostics;

 static void Main(string[] args)
        {
            ReportError();
            ReportError();
            ReportError();
            ReportError();
            Console.ReadLine();
        }

        private static void ReportError()
        {
            StackFrame callStack = new StackFrame(1, true);
            Console.WriteLine(callStack.GetFileLineNumber());
        }

 

posted @ 2020-10-10 20:34  FredGrit  阅读(111)  评论(0编辑  收藏  举报