Csharp/C Sharp/Reflection/Version

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Demonstrates retrieving version information

<source lang="csharp"> /* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110

  • /

/*

 Example16_4.cs demonstrates retrieving version information
  • /

using System; using System.Reflection; [assembly:AssemblyVersionAttribute("1.2.3.4")] [assembly:AssemblyTitleAttribute("Example 16_4")] public class Example16_4 {

   public static void Main() 
   {
       // get the version object for this assembly
       Version v = System.Reflection.Assembly.GetExecutingAssembly().
        GetName().Version;
       // write out the whole version number
       Console.WriteLine(v.ToString());
       // or do it in pieces
       Console.WriteLine(v.Major + "." + v.Minor + "." + v.Build + 
        "." + v.Revision);
       
       // now get an external assembly
       AssemblyName anm = AssemblyName.GetAssemblyName( 
        "c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
       // and show its version
       Console.WriteLine(anm.Version.ToString());
   }

}

      </source>