次要版本仅返回c#中的单个数字 [英] Minor version returns only single digit in c#
问题描述
在我的控制台应用程序中,我的要求是I / P:版本:10.01
In my console application my requirement was I/P: Version : 10.01
预计O / P:
Expected O/P:
主要版本:10
Major Version : 10
次要版本:01(预期实际) 但作为次要版本返回:1
Minor Version : 01(Actual Expected) but returns as Minor Version :1
Console.Write("Enter the version : ");
var readVersion = Console.ReadLine();
Version version = new Version(readVersion);
Console.WriteLine("Major Version : " + version.Major);
Console.WriteLine("Minor Version : " + version.Minor);
注意:它在我的经理机器上工作正常
Note: It works fine in my manager machine
你能否分享一下这方面的知识? Advace谢谢。
Could you please share the knowledge on this ? Advace thanks.
推荐答案
嗨Balakrishnan,
Hi Balakrishnan,
你看到这个是因为version.Minor只返回一个int属性,而不是一个字符串。这意味着如果你想以这种方式看到它们,你必须在显示期间自己格式化前面零的数量。
You are seeing this because version.Minor simply returns an int property, and not a string. Which means that you will have to format the number of preceding zero's on your own during the display if you want to see them that way.
Version version = new Version("10.01");
Console.WriteLine("Major Version : " + version.Major);
Console.WriteLine("Minor Version : " + version.Minor.ToString("00"));
Console.Read();
这将打印出来:
主要版本:10
次要版本:01
快乐编码!
这篇关于次要版本仅返回c#中的单个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!