Does anyone know if you can use the comparison operators like ==, >=, <=, >, < etc... on two different System.Version objects to detect different versions and in what direction (like which of the two is a newer version vs older?)

6 Years
Discussion Span
Last Post by zachattack05

I believe that it doesn't (although I could be wrong). However you can extend the class and override those operators to suit your needs.


System.Version cannot be inherited. But it already has the operators overloaded.
Higher version numbers are greater than lower version numbers. Higher version numbers are newer, if you are doing it right.

Votes + Comments
Thanks for the correction and explanation :)

Depents what type are these different versions. If they are both numbers you can use:
==, >=, <=, >, < (all of them).
If they are a string you cannot use any. Becuase it will simply not work. YOu cannot compare the difference in the string, you can only compare if they are same (or different) lenght, or they are equal (or not); meaning if they are really equal (like: "aaa" == "aaa" > true, "aaa" != "aaa" > false, "aaa" == "aab" > false

You see the difference?


Great. Thanks!

I was looking for a way to put a command version in each command I send over the network so if/when different versions of a command set come out, if something changes, the server still will have backwards capabilities. Guess I'll use something other than System.Version for this.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.