Reputation: 71
What I am trying to do is display my version number, but I want to display it like:
1.2.1
But it displays 1.2.1.0
. I don't want the fourth digit to show at all and I'm not sure how to do this.
This is what I have tried:
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
labelControl5.Text = String.Format("Project Sachiko {0}", version);
Upvotes: 3
Views: 1483
Reputation:
You can use this:
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
return $"{version.Major}.{version.Minor}.{version.Build}";
Upvotes: 1
Reputation: 37095
There´s an overload for Version.ToString
that accepts an int as parameter in order to print only the first three parts for example:
labelControl5.Text = String.Format("Project Sachiko {0}", version.ToString(3));
Upvotes: 3
Reputation: 797
Use version.ToString(3)
to display only Major.Minor.Build
version without Revision
. For more information on formatting versions, see MSDN: Version.ToString
Upvotes: 6