elfenliedtopfan5
elfenliedtopfan5

Reputation: 71

How to display version number a certain way

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

Answers (3)

user12031933
user12031933

Reputation:

You can use this:

var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
return $"{version.Major}.{version.Minor}.{version.Build}";

Upvotes: 1

MakePeaceGreatAgain
MakePeaceGreatAgain

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

misticos
misticos

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

Related Questions