Monday, September 9, 2013

Useful tip on determining if a version represented as a string is greater than another

The Version class allows you to do something like this:

Version a = new Version("1.0.0.0");
Version b = new Version("1.0.0.1");

if (b>a) //evaluates to true
    blah blah blah

Being able to use pretty much any comparison operator on a Version object like this is really useful.

The MSDN page also includes this useful bit on getting the version of the current running assembly:

     Assembly assem = Assembly.GetEntryAssembly();
  AssemblyName assemName = assem.GetName();
  Version ver = assemName.Version;
  Console.WriteLine("Application {0}, Version {1}", assemName.Name, ver.ToString());

No comments:

Post a Comment