int result = version1.CompareTo(version2); if (result < 0) { // version1 is less than version2 } else if (result == 0) { // version1 is equal to version2 } else { // version1 is greater than version2 }
Version requiredVersion = new Version("5.2.3"); Version installedVersion = typeof(Microsoft.AspNet.Mvc.Controller).Assembly.GetName().Version; if (installedVersion.CompareTo(requiredVersion) >= 0) { Console.WriteLine("Microsoft.AspNet.Mvc version 5.2.3 or later is installed."); } else { Console.WriteLine("Microsoft.AspNet.Mvc version 5.2.3 or later is not installed."); }In this example, we are checking the version number of the Microsoft.AspNet.Mvc assembly, which is part of the ASP.NET MVC framework. If the installed version is equal to or greater than 5.2.3, a message is displayed indicating that the required version is installed. Otherwise, a different message is displayed indicating that the required version is not installed. The package library that contains the System Version CompareTo method is the .NET Framework Class Library. It is part of the Microsoft .NET Framework and provides a set of standard APIs for building .NET applications.