📜  使用 GetExecutingAssembly() 方法打印当前程序集名称的 C# 程序

📅  最后修改于: 2022-05-13 01:54:34.624000             🧑  作者: Mango

使用 GetExecutingAssembly() 方法打印当前程序集名称的 C# 程序

在 C# 中,GetExecutingAssembly() 方法是 Assembly 类的方法。此方法返回包含当前正在执行的代码的程序集。要使用这种方法,我们必须在程序中使用 System.Reflection。

语法

public static System.Reflection.Assembly GetExecutingAssembly ();

它将返回当前程序程序集、版本、文化和 PublicKeyToken。

示例 1

C#
// C# program to display the current assembly name 
using System;
using System.Reflection;
  
class GFG{
      
static void Main(string[] args)
{
    Console.WriteLine("Current assembly contains:");
    
    // Get the executing assembly
    // Using GetExecutingAssembly() method
    Console.WriteLine(Assembly.GetExecutingAssembly());
}
}


C#
// C# program to display the current assembly name 
using System;
using System.Reflection;
  
class GFG{
      
static void Main(string[] args)
{
      
    // Get the executing assembly 
    // with FullName property
    // FullName property is use 
    // to print the name of the assembly
    Console.WriteLine(Assembly.GetExecutingAssembly().FullName);
}
}


输出:

Current assembly contains:
main, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

示例 2:

C#

// C# program to display the current assembly name 
using System;
using System.Reflection;
  
class GFG{
      
static void Main(string[] args)
{
      
    // Get the executing assembly 
    // with FullName property
    // FullName property is use 
    // to print the name of the assembly
    Console.WriteLine(Assembly.GetExecutingAssembly().FullName);
}
}

输出:

main, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null