1,. Disclaimer: This article is reproduced from http://www.cnblogs.com/lvdongjie/p/5777330.html
2. Engineering Code:
Class Program
{
static void Main (string[] args)
{
Console.WriteLine (Getcursourcefilename () + "," +getlinenum ());
Console.ReadLine ();
}
Which line of the current source code is obtained
</summary>
<returns></returns>
public static int Getlinenum ()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace (1, true);
Return St. GetFrame (0). Getfilelinenumber ();
}
<summary>
Fetch the source file name of the current source code
</summary>
<returns></returns>
public static string Getcursourcefilename ()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace (1, true);
Return St. GetFrame (0). GetFileName ();
}
}
3. Experimental phenomena:
C # Gets the file name of the currently running source code and the method of the current source line number