using System.Collections.Generic;
public static void Main()
string[] versionStrings = new [] {"3.5.25569", "2.5.25557", "2.5.25580", "2.5.25569", "2.4.25569"};
IEnumerable<VersionNumber> versions = versionStrings.Select(s => VersionNumber.Parse(s));
IOrderedEnumerable<VersionNumber> sorted = versions.OrderBy(v => v);
foreach (var res in sorted) {
public class VersionNumber : IComparable {
public int Major { get; set; }
public int Minor { get; set; }
public int Revision { get; set; }
public static VersionNumber Parse(string s) {
if (string.IsNullOrWhiteSpace(s)) {
throw new ArgumentNullException();
var result = new VersionNumber();
var parts = s.Split(new [] {'.'});
if (parts.Count() != 3) {
throw new ArgumentException("Input string must be in format 'X.Y.ZZZZZ'.");
result.Major = int.Parse(parts[0]);
result.Minor = int.Parse(parts[1]);
result.Revision = int.Parse(parts[2]);
catch (FormatException) {
throw new ArgumentException("Input string must be in format 'X.Y.ZZZZZ', with X, Y, Z integers.");
public int CompareTo(object obj) {
if (obj == null) return 1;
VersionNumber otherVersion = obj as VersionNumber;
if (otherVersion == null) {
throw new ArgumentException("Object is not a VersionNumber");
var result = Major.CompareTo(otherVersion.Major);
result = Minor.CompareTo(otherVersion.Minor);
result = Revision.CompareTo(otherVersion.Revision);
public override string ToString() {
return Major + "." + Minor + "." + Revision;