This documentation is archived and is not being maintained.

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.

[Visual Basic]
Public Overridable Function GetFileLineNumber() As Integer
[C#]
public virtual int GetFileLineNumber();
[C++]
public: virtual int GetFileLineNumber();
[JScript]
public function GetFileLineNumber() : int;

Return Value

The file line number.

-or-

Zero if the file line number cannot be determined.

Example

[Visual Basic, C#, C++] The following code example demonstrates how you can use the GetFileLineNumber method.

[Visual Basic] 
' Display the stack frame properties.
Dim sf As StackFrame = st.GetFrame(i)
Console.WriteLine(" File: {0}", sf.GetFileName())
Console.WriteLine(" Line Number: {0}", _
   sf.GetFileLineNumber())
' 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())
End If
If sf.GetNativeOffset <> StackFrame.OFFSET_UNKNOWN
  Console.WriteLine(" Native Offset: {0}", _
      sf.GetNativeOffset())
End If

[C#] 
// 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());
}

[C++] 
// Display the stack frame properties.
StackFrame *sf = st->GetFrame(i);
Console::WriteLine(S" File: {0}", sf->GetFileName());
Console::WriteLine(S" Line Number: {0}", 
   sf->GetFileLineNumber().ToString());
// Note that the column number defaults to zero
// when not initialized.
Console::WriteLine(S" Column Number: {0}", 
   sf->GetFileColumnNumber().ToString());
Console::WriteLine(S" Intermediate Language Offset: {0}", 
   sf->GetILOffset().ToString());
Console::WriteLine(S" Native Offset: {0}", 
   sf->GetNativeOffset().ToString());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

StackFrame Class | StackFrame Members | System.Diagnostics Namespace

Show: