void DisplayCallerColumn() { StackFrame frame = new StackFrame(1); int columnNumber = frame.GetFileColumnNumber(); Console.WriteLine("The calling method's code starts in column {0}", columnNumber); }
class Program { static void Main(string[] args) { MethodA(); } static void MethodA() { MethodB(); } static void MethodB() { StackFrame frame = new StackFrame(1); int columnNumber = frame.GetFileColumnNumber(); Console.WriteLine("The calling method's code starts in column {0}", columnNumber); } }In this example, the Main method calls MethodA, which in turn calls MethodB. When MethodB is called, it creates a new StackFrame object with an argument of 1 (meaning the caller of MethodB), and calls GetFileColumnNumber to retrieve the column number of the file that contains the code for the calling method. The System.Diagnostics namespace is part of the .NET Framework.