How can I compare version string in the format of x.x.x.x
e.g. compare 3.0.1750
to 3.0.1749
meaning
if (3.0.1750 > 3.0.1749)
{
// do this
}
How can I compare version string in the format of x.x.x.x
e.g. compare 3.0.1750
to 3.0.1749
meaning
if (3.0.1750 > 3.0.1749)
{
// do this
}
Use the Version
class to compare between versions:
var v1 = new Version("3.0.1750");
var v2 = new Version("3.0.1749");
bool isV1Greater = v1 > v2; // true
bool isV2Greater = v1 < v2; // false
You can use class Version
to achieve that. Here is a sample of how to use it from MSDN:
Version v1 = new Version(2, 0);
Version v2 = new Version("2.1");
Console.Write("Version {0} is ", v1);
switch(v1.CompareTo(v2))
{
case 0:
Console.Write("the same as");
break;
case 1:
Console.Write("later than");
break;
case -1:
Console.Write("earlier than");
break;
}
Console.WriteLine(" Version {0}.", v2);