Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

StackFrame.GetFileLineNumber Method

Gets the line number in the file that contains the code that is executing. This information is typically extracted from the debugging symbols for the executable.

Namespace: System.Diagnostics
Assembly: mscorlib (in mscorlib.dll)

public virtual int GetFileLineNumber ()
public int GetFileLineNumber ()
public function GetFileLineNumber () : int

Return Value

The file line number. -or- Zero if the file line number cannot be determined.

The following code example demonstrates how you can use the GetFileLineNumber method.

// Display the stack frame properties.
StackFrame sf = st.GetFrame(i);
Console.WriteLine(" File: {0}", sf.GetFileName());
Console.WriteLine(" Line Number: {0}", 
   sf.GetFileLineNumber());
// Note that the column number defaults to zero
// when not initialized.
Console.WriteLine(" Column Number: {0}", 
   sf.GetFileColumnNumber());
if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
{
   Console.WriteLine(" Intermediate Language Offset: {0}", 
      sf.GetILOffset());
}
if (sf.GetNativeOffset() != StackFrame.OFFSET_UNKNOWN)
{
   Console.WriteLine(" Native Offset: {0}", 
      sf.GetNativeOffset());
}

// Display the stack frame properties.
StackFrame sf = st.GetFrame(i);
Console.WriteLine(" File: {0}", sf.GetFileName());
Console.WriteLine(" Line Number: {0}", (
    Int32)sf.GetFileLineNumber());

// Note that the column number defaults to zero
// when not initialized.
Console.WriteLine(" Column Number: {0}", 
    (Int32)sf.GetFileColumnNumber());
if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN) {
    Console.WriteLine(" Intermediate Language Offset: {0}", 
        (Int32)sf.GetILOffset());
}
if (sf.GetNativeOffset() != StackFrame.OFFSET_UNKNOWN) {
    Console.WriteLine(" Native Offset: {0}", 
        (Int32)sf.GetNativeOffset());
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.