How can I prevent System.Version from removing leading zeroes?
c#
Solution
That's how `system.Version` works - it stores the components of the version as separate integers, so there's no distinction between `2.01` and `2.1`. If you need to display it that way you could format it as:
Version versionNo = new Version("2.01");
string s = string.Format("{0}.{1:00}",versionNo.Major, versionNo.Minor);
For convenience you could also create an extension method:
public static string MyFormat(this Version ver)
{
return string.Format("{0}.{1:00}",ver.Major, ver.Minor);
}
That way you can still customize the display while retaining the comparability of the `Version` class.
Problem
``` var versionNo = new System.Version("2.01"); ``` I am getting the value `versionNo` = `2.1`, but I want it as `2.01`. Any suggestions, please?