I have to store versionName of a template. VersionName is autoincremented.If last versionName is "Version 1.0", next should be "version 2.0". First time when a template is created, I have to store "Version 1.0".
I am using
VersionName = "Version "+((LatestVersion+1).ToString())
LatestVersion holds the last version which is 0 in case added for first time.
This seems to be a ugly workaround and doesnot even yield Version 1.0. i开发者_StackOverflow社区t yields Version 1. I Tried with Version class as well,it does not work. How to accomplish this.Please suggest
string.Format("Version {0}.0", LatestVersion + 1);
Assuming you never want anything other than .0
.
The Version
property under the Assembly
has an overloaded ToString()
method that will return various formattings.
VersionName = string.Format("Version {0:d1}", LatestVersion+1);
If it is soo simple (no minor versions) then
string.Format("Version {0}.0", LatestVersion+1);
If you do not want to use minor version (1.X) you could do this:
VersionName = "Version " + (LatestVersion + 1).toString() + ".0";
if you want to be able to use both Major (X.1) numbers and minors you could make a simple function like this for it:
SetVersionName(int Latest,int Minor = 0)
{
VersionName = "Version " + (LatestVersion + 1).toString() + "." + Minor.toString;
}
then you could call SetVersionName(LatestVersion); to get "Version 1.0" or: int MinorVersion = 2; SetVersionName(LatestVersion,MinorVersion); to get "Version 1.2"
you can also use AssemblyInfo to get the app version set in the application file and add .toString() on that.
精彩评论