2

I need to keep track of an arbitrary version number in my C# application, which has the form M+.m+.b+, where M is "Major", m is "minor", b is "build", and + indicates that the version number is not restricted to one digit per number.

Is there a built-in class that basically just holds 3 or 4 (the 4th would be the revision number) ints and provides some convenient comparison functions, or do I need to write my own? I imagine it would look something like this:

class VersionNumber
{
    public int Major;
    public int Minor;
    public int Build;
    public int Revision;

    static public VersionNumber operator >(VersionNumber number)
    {
        // Comparison function here.
    }

    // Other comparison functions and whatnot here.
}
Eric Dand
  • 1,106
  • 13
  • 37
  • 5
    You are looking for the [Version Class](https://msdn.microsoft.com/en-us/library/System.Version(v=vs.110).aspx) I think. Specifically the [Revision](https://msdn.microsoft.com/en-us/library/system.version.revision(v=vs.110).aspx) property and the [Build](https://msdn.microsoft.com/en-us/library/system.version.build(v=vs.110).aspx) property. – Icemanind May 28 '15 at 21:23
  • Check this: `System.Reflection.Assembly.GetExecutingAssembly().GetName().Version` which returns a version object. – Quality Catalyst May 28 '15 at 21:24
  • Ahhh, thanks you two. I'd accept either of these comments as answers if you posted them as such. – Eric Dand May 28 '15 at 21:25

1 Answers1

6

Check this MSDN Link: Version Class. The type System.Version comes with these properties:

  • Build
  • Major
  • MajorRevision
  • Minor
  • MinorRevision
  • Revision
Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62