Author: Maliha Atteeq
Download Source Code : 1015_version.zip
In this simple article you will learn that how to use and initialize the object of version with the help of different constructors Version class in vb and C #.net.
Version:
Version represents the version number for a common language runtime assembly. This class cannot be inherited. Version objects are used to store and compare the version number of an assembly. Note that you or an application can set a Version object to the version number of an assembly. Version numbers consist of two to four components: major, minor, build, and revision. The major and minor components are required; the build and revision components are optional.
Initialization:
In order to initialize the object of version, version class provides us five constructors.
First constructor:
The first overloaded constructor is the blank constructor. It takes no argument as a parameter.
To demonstrate make a new window application. Drag one button on from.
Now write the following code on Button click event:
C#:
private void btn_build_Click(object sender, EventArgs e)
{
System.Version obj = new Version();
MessageBox.Show("an object of version is created using blank constructor");
}
VB:
Private Sub btn_build_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim obj As System.Version = New Version()
MessageBox.Show("an object of version is created using blank constructor")
End Sub
Second constructor:
The second overloaded constructor takes one string argument as a parameter. The string type argument defines the version in terms of string which includes the major, minor, revision number all separated by dot(.).
To demonstrate make a new window application. Drag one button and one text box on from.
Now write the following code on Button click event:
C#:
private void button1_Click(object sender, EventArgs e)
{
String str;
str = txt_verstr.Text;
System.Version obj;
obj = new Version(str);
MessageBox.Show("an object of version is created having string version= "+str);
}
VB:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim str As [String]
str = txt_verstr.Text
Dim obj As System.Version
obj = New Version(str)
MessageBox.Show("an object of version is created having string version= " & str)
End Sub
Third constructor:
The third overloaded constructor takes two integer arguments as a parameter. The first argument is major and the second is the minor.
To demonstrate make a new window application. Drag one button and two text boxes on from.
Now write the following code on Button click event:
C#:
private void button1_Click_1(object sender, EventArgs e)
{
int major;
int minor;
System.Version obj;
major = Convert.ToInt16(txt_major.Text);
minor = Convert.ToInt16(txt_minor.Text);
obj = new Version(major, minor);
MessageBox.Show("an object of version is created having mjor= "+Convert.ToString(major)+" and having minor= "+Convert.ToString(minor));
}
VB:
Private Sub button1_Click_1(ByVal sender As Object, ByVal e As EventArgs)
Dim major As Integer
Dim minor As Integer
Dim obj As System.Version
major = Convert.ToInt16(txt_major.Text)
minor = Convert.ToInt16(txt_minor.Text)
obj = New Version(major, minor)
MessageBox.Show(("an object of version is created having mjor= " & Convert.ToString(major) & " and having minor= ") + Convert.ToString(minor))
End Sub
Fourth constructor:
The fourth overloaded constructor takes three integer arguments as a parameter. The first argument is major and the second is the minor and the third argument is build.
To demonstrate make a new window application. Drag one button and three text boxes on from.
Now write the following code on Button click event:
C#:
private void btn_build4_Click(object sender, EventArgs e)
{
int min;
int maj;
int build;
System.Version obj;
min = Convert.ToInt16(txt_minr.Text);
maj = Convert.ToInt16(txt_majr.Text);
build = Convert.ToInt16(txt_bild.Text);
obj = new Version(maj, min, build);
MessageBox.Show("an object of version is created having mjor= " + Convert.ToString(maj) + " and having minor= " + Convert.ToString(min)+" and build= "+Convert.ToInt16(build));
}
VB:
Private Sub btn_build4_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim min As Integer
Dim maj As Integer
Dim build As Integer
Dim obj As System.Version
min = Convert.ToInt16(txt_minr.Text)
maj = Convert.ToInt16(txt_majr.Text)
build = Convert.ToInt16(txt_bild.Text)
obj = New Version(maj, min, build)
MessageBox.Show((("an object of version is created having mjor= " & Convert.ToString(maj) & " and having minor= ") + Convert.ToString(min) & " and build= ") + Convert.ToInt16(build))
End Sub
Fifth constructor:
The fifth overloaded constructor takes four integer arguments as a parameter. The first argument is major and the second is the minor and the third argument is build and the fourth argument is revision number.
To demonstrate make a new window application. Drag one button and four text boxes on from.
Now write the following code on Button click event:
C#:
private void btn_build5_Click(object sender, EventArgs e)
{
int min;
int maj;
int build;
int rev;
System.Version obj;
min = Convert.ToInt16(txt_min.Text);
maj = Convert.ToInt16(txt_maj.Text);
build = Convert.ToInt16(txt_build.Text);
rev = Convert.ToInt16(txt_rev.Text);
obj = new Version(maj, min, build,rev);
MessageBox.Show("an object of version is created having mjor= " + Convert.ToString(maj) + " and having minor= " + Convert.ToString(min) + " and build= " +Convert.ToString(build)+" and revision number= "+Convert.ToString(rev));
}
VB:
Private Sub btn_build5_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim min As Integer
Dim maj As Integer
Dim build As Integer
Dim rev As Integer
Dim obj As System.Version
min = Convert.ToInt16(txt_min.Text)
maj = Convert.ToInt16(txt_maj.Text)
build = Convert.ToInt16(txt_build.Text)
rev = Convert.ToInt16(txt_rev.Text)
obj = New Version(maj, min, build, rev)
MessageBox.Show(((("an object of version is created having mjor= " & Convert.ToString(maj) & " and having minor= ") + Convert.ToString(min) & " and build= ") + Convert.ToString(build) & " and revision number= ") + Convert.ToString(rev))
End Sub
Now write the following code on FORM LOAD event:
C#:
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "DEVASP VERSION APPLICATION";
}
Vb:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.Text = "DEVASP VERSION APPLICATION"
End Sub
This simple article tells that how to use and initialize the object of version with the help of different constructors Version class in vb and C #.net.