1

I am trying to assign the HttpResponseMessage.Version with the value of "1.07" (actually it's a value that service returns. It's not a fixed value. This is just an example value.) and I tried using the below code but it returns the value as 1.7 .

  string input = "1.07"
  Version ver = null;
  if (Version.TryParse(input, out ver))
     Console.WriteLine("Converted '{0} to {1}.", input, ver);

I think it's the behavior of the Version class , but is there any work around for this problem ?

The problem is the HttpResponseMessage.Version only takes the version data type value.If I convert that to string, again converting it back to the version datatype is ignoring that leading zero.

krrishna
  • 2,050
  • 4
  • 47
  • 101
  • I think you are confusing the value with how it is displayed. You can always force leading zeros with `String.Format` or `int.ToString`. https://msdn.microsoft.com/en-us/library/dd260048%28v=vs.110%29.aspx – Tim Schmelter Feb 09 '15 at 15:29
  • According to your last update, there is absolutely no difference between a version `1.07` and `1.7` since the minor version is an `int`-property which has no concept of leading zeros. Since [`HttpResponseMessage.Version`](https://msdn.microsoft.com/en-us/library/system.net.http.httpresponsemessage.version%28v=vs.118%29.aspx) is just a plain `Version` you don't be afraid of "missing" leading zeros. So again, you culd use `ver.Minor.ToString("D2")` to get the leading zero in the minor version if you want. – Tim Schmelter Feb 09 '15 at 15:43
  • ... another way: `string.Format("{0}.{1:d2}", ver.Major, ver.Minor)` – Tim Schmelter Feb 09 '15 at 15:50

0 Answers0