Version Checking with System.Version

The .Net Framework makes version checking extremely simple. The framework provides a Version class that implements IComparable. Comparing two versions is as easy as the code below:

using System;

namespace VersionChecker {
    class Program {
        static void Main(string[] args) {
            Version v1 = new Version("1.0.0.0");
            Version v2 = new Version("1.0.0.1");

            if (v1 > v2) {
                Console.WriteLine("v1 is higher");
            } else {
                Console.WriteLine("v2 is higher");
            }

            Console.ReadLine();
        }
    }
}

Here’s the result:

image

Leave a Reply