C#获取当前程序集Assembly的文件名

C# Code:

string  codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase;
返回结果:"file:///c:/users/administrator/documents/visual studio 2015/Projects/WindowsFormsApplication4/WindowsFormsApplication4/bin/Debug/WindowsFormsApplication4.EXE"  

string  file = Assembly.GetExecutingAssembly().GetName().Name;
返回结果:"WindowsFormsApplication4"  

string  location = Assembly.GetExecutingAssembly().Location;
返回结果:"c:\\users\\administrator\\documents\\visual studio 2015\\Projects\\WindowsFormsApplication4\\WindowsFormsApplication4\\bin\\Debug\\WindowsFormsApplication4.exe"  

string  fileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
返回结果:"WindowsFormsApplication4.exe"

你可能感兴趣的:(C#基础语法)