X

Using Version Class

When dealing with version numbers we often need to convert them to string and vice versa. There is lot of code where versions are handled manually in code. I don’t know why. But I know for sure there is class called Version and I’m sure this class will help us a lot. Let’s see a little example.

The following code:

Version ver = new Version("1.4");
Console.WriteLine("Major: " + ver.Major.ToString());
Console.WriteLine("Minor: " + ver.Minor.ToString());
Console.WriteLine("String: " + ver.ToString());
Console.ReadLine();

outputs something like this:

Major: 1

Minor: 4

String: 1.4

As we can see, this class makes using versions very easy. There is one nasty limitation – Version class is sealed. If there is need for non-sealed class then you should write it by yourself.

Liked this post? Empower your friends by sharing it!
Categories: C#

View Comments (1)

Related Post