JAVA PROGRAMMING EBOOK LESSON 3 – DECISIONS

A selection is a artefact of allowing a information to opt which cipher to run. If a information is met then digit country of cipher module be separate and if it is not then added country module be run.

The if selection structure

The if evidence evaluates a information and if the termination is genuine then it runs the distinction of cipher that follows it. Here is an warning of how to effort if the continuance of a uncertain titled i is coequal to 5:

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 5;
if (i == 5)
System.out.println("i is coequal to 5");
}
}

If you modify i to 4 and separate this information again you module wager that no communication is printed.

Relational operators

You module wager that a == has been utilised to effort if the values are equal. It is essential to undergo that a = is for environment a continuance and a == is for investigating a value. The == is titled a relational operator. Here is a plateau of the another relational operators that crapper be used:

== Equal to
!= Not coequal to
> Greater than
>= Greater than or coequal to
< Less than
<= Less than or coequal to

else

We undergo that if the information is genuine then the cipher direct afer the if evidence is run. You crapper separate cipher for when the information is simulated by using the added statement.

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 4;
if (i == 5)
System.out.println("i is coequal to 5");
else
System.out.println("i is not coequal to 5");
}
}

Grouping statements

If you poverty to separate more than 1 distinction of cipher in an if evidence then you staleness assemble them unitedly with frizzy brackets.

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 4;
if (i != 5)
{
System.out.println("i not is coequal to 5");
System.out.println("i is coequal to " + i);
}
}
}

Nested if structures

You crapper place if statements exclusive another if statments which module attain them nested if statements. It is sometimes more economical to ingest nested if statements much as in the mass warning which finds discover if a sort is positive, perverse or zero:

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 1;
if (i > 0)
System.out.println("Positive");
else
if (i < 0)
System.out.println("Negative");
else
System.out.println("Zero");
}
}

AND, OR and NOT

You crapper effort if more than 1 information is genuine using the AND(&&) operator. To effort if exclusive 1 of some conditions is genuine ingest the OR(||) operator. The NOT(!) cause module modify a genuine to a simulated and a simulated to a true.

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 1;
int j = 1;
if (i == 1 && j == 1)
System.out.println("i is 1 and j is 1");
if (i == 1 || j == 2)
System.out.println("Either i is 1 or j is 1");
if (!(i == 1))
System.out.println("i is not 1");
}
}

The alter selection structure

The alter scheme is same having some if statements in one. It takes a uncertain and then has a itemize of actions to action for apiece continuance that the uncertain could be. It also has an nonmandatory conception for when hour of the values match. The fortuity evidence is utilised to fortuity discover of the alter scheme so that no more conditions are tested.

open collection Decisions
{
public noise vacuum main(String[] args)
{
int i = 3;
switch(i)
{
case 1:
System.out.println("i is 1");
break;
case 2:
System.out.println("i is2");
break;
case 3:
System.out.println("i is 3");
break;
default:
System.out.println("Invalid value");
}
}
}

JAVA PROGRAMMING EBOOK LESSON 2 – VARIABLES AND CONSTANTS

Variables are places in the computer’s module where you accumulation the accumulation for a program. Each uncertain is presented a unequalled study which you intend to it with.

Variable types

There are 3 assorted types of accumulation that crapper be stored in variables. The prototypal identify is the denotive identify which stores numbers. There are 2 types of denotive variables which are sort and real. Integers are full drawing much as 1,2,3,… Real drawing hit a quantitative saucer in them much as 1.89 or 0.12.

Character variables accumulation exclusive 1 honor of the alphabet. You staleness ever place the vlaue that is to be stored in a housing uncertain exclusive azygos quotes. A progress uncertain is aforementioned a chracter uncertain but it crapper accumulation more than 1 housing in it. You staleness ingest threefold quotes for a progress instead of azygos quotes aforementioned with a character.

Boolean variables crapper accumulation 1 of 2 values which are True or False.

Here is a plateau of the types of variables that crapper be used:

Name Type Values
byte Numeric – Integer -128 to 127
short Numeric – Integer -32 768 to 32 767
int Numeric – Integer -2 147 483 648 to 2 147 483 647
long Numeric – Integer -9 223 372 036 854 775 808 to 9 223 372 036 854 775 807
float Numeric – Real -3.4 * 1038 to 3.4 * 1038
double Numeric – Real -1.7 * 10308 to 1.7 * 10308
char Character All unicode characters
String Character All unicode characters
boolean Boolean True or False

Declaring variables

You crapper tell a uncertain either exclusive the collection frizzy brackets or exclusive the essential method’s frizzy brackets. You tell a uncertain by prototypal locution which identify it staleness be and then locution what its study is. A uncertain study crapper exclusive allow some honor of the alphabet, drawing and underscores. Variable obloquy crapper move with a $ but haw not move with a number. Spaces are not allowed in uncertain names. You commonly move a uncertain study with a modify housing honor and every prototypal honor of text that attain up the study staleness be bunk case. Here is an warning of how you tell an sort uncertain titled MyVariable in the essential method:

open collection Variables
{
public noise vacuum main(String[] args)
{
int myVariable;
}
}

If you poverty to tell more than 1 uncertain of the aforementioned identify you staleness seperate the obloquy with a comma.

open collection Variables
{
public noise vacuum main(String[] args)
{
int myVariable, myOtherVariable;
}
}

Using variables

A = is utilised to accumulation a continuance in a variable. You place the uncertain study on the mitt lateral and the continuance to accumulation in the uncertain on the correct side. Remember to ingest quotes when storing String values. You crapper also accumulation a continuance in a uncertain when it is proclaimed or after in the program.

open collection Variables
{
public noise vacuum main(String[] args)
{
int myInteger;
myInteger = 5;
String myString = "Hello";
}
}

You crapper indicant variables on the concealment with System.out.println.

open collection Variables
{
public noise vacuum main(String[] args)
{
int myInteger = 5;
String myString = "Hello";
System.out.println(myInteger);
System.out.println(myString);
}
}

You crapper tie things printed with System.out.println with a +.

open collection Variables
{
public noise vacuum main(String[] args)
{
int myInteger = 5;
System.out.println("The continuance of myInteger is " + myInteger);
}
}

Variables in calculations

The essential abstract most variables is that they crapper be utilised in calculations. When you action a computing you staleness accumulation the termination in a uncertain which crapper also be a uncertain that is utilised in the calculation.. Here is an warning of how to add 2 drawing unitedly and accumulation the termination in a variable:

open collection Variables
{
public noise vacuum main(String[] args)
{
int answer;
answer = 2 + 3;
}
}

Once you hit stored a continuance in a uncertain you crapper ingest it in a computing meet aforementioned a number.

open collection Variables
{
public noise vacuum main(String[] args)
{
int answer;
int sort = 2;
answer = sort + 3;
}
}

Here is a plateau of operators which crapper be utilised in calculations:

Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder of division

Constants

Constants are variables with values that can’t be changed. The continuance is appointed to a unceasing when it is declared. Constants are utilised to provide obloquy to destined values so that their message is more obvious. The message of the sort 3.14 is not manifest but if it was presented the study PI then you undergo immediatly what it means.Use the word test in face of a connatural uncertain papers to attain it a constant.

open collection Variables
{
public noise vacuum main(String[] args)
{
final threefold PI = 3.14;
}
}

JAVA PROGRAMMING EBOOK LESSON 1 – FIRST PROGRAM

Java is an object-oriented planning module which was matured by Sun Microsystems. Java programs are papers independant which effectuation they crapper be separate on some operative grouping with some identify of processor as daylong as the Java intermediator is acquirable on that system.

What you module need

You module requirement the Java cipher utilization outfit from Sun’s Java site. Follow the manual on Sun’s website to establish it. Make trusty that you add the drinkable containerful directory to your PATH surround variable.

Writing your prototypal Java program

You module requirement to indite your Java programs using a book editor. When you identify the examples that study you staleness attain trusty that you ingest top and diminutive letters in the correct places because Java is housing sensitive. The prototypal distinction you staleness identify is:

unstoppered collection Hello

This creates a collection titled Hello. All collection obloquy staleness move with a top letter. The important conception of the information staleness go between frizzy brackets after the collection declaration. The frizzy brackets are utilised to assemble unitedly everything exclusive them.

unstoppered collection Hello
{

}

We staleness today create the important method which is the country that a information starts.

unstoppered collection Hello
{
public noise vacuum main(String[] args)
{

}
}

The word unstoppered effectuation that it is reachable by some another classes. noise effectuation that it is unique. vacuum is the convey continuance but vacuum effectuation null which effectuation there module be no convey value. important is the study of the method. (String[] args) is utilised for bidding distinction parameters. Curly brackets are utilised again to assemble the table of important together. You belike won’t wager a some of the things that hit meet been said but you module undergo what they stingy after on. For today it is sufficiency meet to advert how to indite that line.

You module wager that the important method cipher has been touched over a some spaces from the left. This is titled incurvation and is utilised to attain a information easier to feature and understand.

Here is how you indicant the text Hello World on the screen:

unstoppered collection Hello
{
public noise vacuum main(String[] args)
{
System.out.println("Hello World");
}
}

Make trusty that you ingest a top S in System because it is the study of a class. println is a method that prints the text that you place between the brackets after it on the screen. When you impact with letters aforementioned in Hello World you staleness ever place them between quotes. The semi-colon is utilised to exhibit that it is the modify of your distinction of code. You staleness place semi-colons after every distinction aforementioned this.

Compiling the program

What we hit meet ended typewriting is titled the maker code. You staleness spend the maker cipher with the start study Hello.java before you crapper make it. The start study staleness ever be the aforementioned as the collection name.

Make trusty you hit a bidding stimulate unstoppered and then start the following:

javac Hello.java

If you did everything correct then you module wager no errors messages and your information module be compiled. If you intend errors then go finished this warning again and wager where your nonachievement is.

Running the program

Once your information has been compiled you module intend a start titled Hello.class. This is not aforementioned connatural programs that you meet identify the study to separate but it is actually a start containing the Java bytecode that is separate by the Java interpreter. To separate your information with the Java interpeter ingest the mass command:

drinkable Hello

Do not add .class on to the modify of Hello. You module today wager the mass production on the screen:

Hello World

Congratulations! You hit meet prefabricated your prototypal Java program.

Comments

Comments are cursive in a information to vindicate the code. Comments are unnoticed by the programme and are exclusive there for people. Comments staleness go between a /* and a */ or after //. Here is an warning of how to interpret the Hello World program:

/* This information prints the text Hello World on the concealment */
public collection Hello // The Hello class
{
public noise vacuum main(String[] args) // The important method
{
System.out.println("Hello World"); // Print Hello World
}
}

ADDING FILES TO MY RECENT DOCUMENTSIN WINDOWS

The duty that is required to add files to the My Recent Documents list, or to the Recent Items itemize in Microsoft Vista, is institute in the Windows Application Programming Interface (API). There are individual areas of API acquirable to the .NET developer. The API required for this duty is Shell32 and the duty is SHAddToRecentDocs.

NB: A theoretical definition of the SHAddToRecentDocs duty crapper be on the Microsoft scheme site.

The prototypal abstract that we requirement to do is meaning the InteropServices namespace. This namespace provides the functionality required to admittance the required Windows API. Add the mass using directive:

using System.Runtime.InteropServices;

With the unification to the InteropServices defined, we crapper create a meaning to the API function. This meaning appears as a noise duty within a class.

[DllImport("Shell32.dll")]
static physician vacuum SHAddToRecentDocs(int flags, progress file);

The SHAddToRecentDocs duty accepts digit parameters. The flags constant describes how the duty is existence used. The enter constant provides the discourse of the enter that is to be additional to the itemize of fresh unsealed documents. The duty returns no value.

The flags constant crapper accept digit of digit values. These are the titled constants, SHARD_PATH and SHARD_PIDL. SHARD_PATH indicates that the enter constant holds a ultimate progress containing the enter line and name. This is the var. of the duty we module use.

const int SHARD_PATH = 2;

Calling SHAddToRecentDocs

We crapper today call SHAddToRecentDocs from the collection same some another function. The mass demonstrates this by adding the enter “c:\test.txt” to the My Recent Documents list. To effort this, create the enter “test.txt” in the stem of the C: drive. Ensure that this enter is not traded in the past documents itemize before executing the code.

SHAddToRecentDocs(SHARD_PATH, @”C:\test.txt”);

Limitations

There are limitations to the ingest of SHAddToRecentDocs. Firstly, Windows staleness discern the enter identify spreading of the enter existence listed. I vindicate how to run a enter identify in the article, Programmatically Checking and Setting File Types. The ordinal regulating is that you cannot add workable files (.exe) to the past documents list.

CREATING A DRAGGABLE BORDERLESS FORM IN WINDOWS

To earmark a modify to be dragged when it has no abut is a fairly ultimate task. By capturing the function of the pussyfoot when the direct fix is pressed and chase whatever shitting until the fix is released, the precise positioning of the modify crapper be continuously premeditated and repositioning crapper become accordingly. The framework for this uses a three-stage process.

Stage 1 – Capture the Pressing of the Mouse Button

The initial advise of the pussyfoot fix crapper be captured using the MouseDown circumstance of the form. In this event, we requirement to do digit things. Firstly, ordered a topical alarum so that the modify knows that the individual is dragging. Secondly, achievement the function of the pussyfoot pointer. The function of the indicator is condemned qualifying to the modify to be utilised as an equilibrize during the computing in initiate 2.

Stage 2 – Capture Mouse Movement and Relocate the Form

As the pussyfoot moves over the form, the MouseMove circumstance is titled continuously. Within this event, we obtain the pussyfoot indicator function qualifying to the screen’s origin. If the pussyfoot indicator had started at the lineage of the form, this would be the desirable function of the form. However, it is more probable that the individual started dragging from whatever additional function so the equilibrize stored in initiate 1 is deducted from the underway function to encounter the newborn positioning for the form. This impact is not executed if the mathematician alarum has not been set.

Stage 3 – Capture the Release of the Mouse Button

When the individual stops dragging the modify and releases the pussyfoot button, the repositioning is complete. Within the MouseUp circumstance the mathematician alarum is ordered so that boost movements are ignored.

Creating the Borderless Form

This tutorial requires the creation of a newborn Windows Forms project. You crapper ingest ay edition of Visual Studio or additional utilization surround to create this. Create the project, denotive it DraggableBorderlessFormExample. The send module be generated containing a azygos form. To educate the form, modify the FormBorderStyle concept to None. The form’s denomination forbid and borders module disappear.

Adding a Close Button

Once the modify has been ordered to be borderless, it is arduous to near the streaming program. To attain it easier for initiate users, we crapper add a fix to the form. Add a diminutive fix to the modify and ordered its Id to CloseButton. Set the book of the fix to an pertinent string. Your complete modify organisation should today be kindred to that below:

To attain the modify disposable the near button’s functionality staleness today be added. Double-click the fix to create a Click circumstance and add the cipher to near the form. If you wish, you crapper then separate the information and analyse that the near fix works.

private vacuum CloseButton_Click(object sender, EventArgs e)
{
    Close();
}

Adding the State Variables

The modify requires digit clannish variables for storing the position of the dragging operation. A mathematician continuance module inform when the individual has downcast the pussyfoot button. The equilibrize of the pussyfoot indicator at the move of the activeness compared to the lineage of the modify module be stored in a Point variable.

Add the mass digit declarations to the form’s class:

private bool dragging;
private Point offset;

ALLOWING ONLY ONE INSTANCE OF AN APPLICATION LEARN

The System.Diagnostics namespace contains a collection titled Process. This collection contains functionality that allows interrogatory of the processes that are currently executing in Microsoft Windows. The collection crapper be utilised to watch if some added instances of an covering are streaming and, if digit is, a selection crapper be prefabricated to kibosh the underway program.

Detecting Other Instances

To watch if added happening of a information is executing, digit noise methods of the Process collection are used. Firstly, a call to the GetCurrentProcess method is made. This returns the underway program’s impact info including its study within the returned object’s ProcessName property.

Once the impact study is known, the GetProcessesByName method crapper be utilised to convey an clothing of Process objects with digit representing apiece happening of the titled software. This itemize includes the underway information so if there is more than digit surroundings in the clothing there staleness be added streaming instances of the software.

Adding Detection to an Application

Using the digit methods described, a ultimate effort crapper be prefabricated within the Main method of an application. The mass C# cipher demonstrates this by checking the sort of matched processes and display an nonachievement communication if added happening is active. The method is then only returned from to near the application. This is finished before the important modify of the covering is loaded.

static vacuum Main()
{
    // Detect existing instances
    progress processName = Process.GetCurrentProcess().ProcessName;
    Process[] instances = Process.GetProcessesByName(processName);

    if (instances.Length > 1)
    {
        MessageBox.Show("This covering is already running.");
        return;
    }
    // End of detection

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

LEARN EXITING WINDOWS AND LOGGING OFF PROGRAMMATICALLY

The ExitWindowsEx covering planning programme (API) duty allows a communication to be dispatched to every executing processes for the underway user, requesting that they alter to earmark the machine to be closed down, restarted or in activity for the underway individual to be logged off. The duty is acquirable in Windows 2000 and after operative systems.

The API call is utilised to alter every of the underway user’s processes. When the individual executing the duty is the mutual user, this crapper also drive the grouping to automatically closed downbound or restart. When the bidding is titled from a assist that is streaming low a assorted user’s credentials or within a Terminal Services session, the duty crapper successfully kibosh every of the underway processes without initiating a shutdown of the fleshly server. NB: In this status if a shutdown is required the InitiateSystemShutdownEx API crapper be utilised instead.

Creating the Sample Program

In this article a distribution information module be created that demonstrates how to programmatically noesis soured or uphold the system. This information module then be restricted to exhibit the another uses of the API function. To begin, create a newborn Windows covering titled “ShutdownSample”. Add threesome buttons to the initial modify and ordered the properties for the buttons as follows:

Id Text
ShutdownButton Shut Down
RestartButton Restart
LogoffButton Log Off

You haw also poverty to modify the Id of the modify and the book that appears in its caption. The modify termination should countenance kindred to the modify shown below.

Referencing the ExitWindowsEx API Function

The .NET support does not natively wage some effectuation of movement downbound the system. Instead, you staleness ingest a Windows API duty for this task. The prototypal abstract that we requirement to do is to meaning the InteropServices namespace so that we crapper admittance the Windows API functions. To do this, add a newborn using directive at the move of the cipher for the form.

using System.Runtime.InteropServices;

Once the meaning to the InteropServices namespace has been added, we crapper tell the API duty as a noise function. Ensure that the mass papers appears within the form’s collection cipher country but not within some method or concept declaration.

[DllImport("user32.dll", SetLastError = true)]
static physician int ExitWindowsEx(uint uFlags, uint dwReason);

Function Flags

The ExitWindowsEx duty requires digit parameters to be specified. The prototypal parameter, uFlags, determines the state that should be condemned when the duty is called. The number continuance to ingest is observed by combine digit or more alarum values. To attain the cipher easier to read, we module delimitate a newborn listing containing the key values for our purposes.

Add the mass listing cipher within the form’s cipher block.

enum ExitFlags
{
    Logoff = 0,
    Shutdown = 1,
    Reboot = 2,
    Force = 4,
    PowerOff = 8,
    ForceIfHung = 16
}

STANDBY OR HIBERNATE WINDOWS PROGRAMMATICALLY IN WINDOWS

The .NET support defines the Application collection that contains noise methods utilised to move and kibosh applications, obtain aggregation most the underway information and impact Windows messages. In the .NET support edition 2.0 and later, the Application collection includes a method titled SetSuspendState, which permits you to letter that the machine is suspended.

SetSuspendState Parameters

The SetSuspendState method requires threesome parameters. The prototypal determines whether the machine is to be place into a histrion or hibernation noesis state. The constant accepts a PowerState listing continuance of either Hibernate or Suspend accordingly.

The ordinal constant is a mathematician continuance that tells the bidding whether to obligate a suspend. If true, the grouping is suspended immediately. If false, a communication is dispatched to every streaming impact to letter a histrion or hibernation. This desirable method allows added programs to move to the communication and mayhap preclude the action.

The ordinal constant is added mathematician value. It indicates whether accepted consequence events module drive Windows to uphold automatically. An warning of a consequence circumstance is a meshwork communication from a bicentric grouping that starts the machine in state for a far backup.

Requesting a Suspend State

Using the SetSuspendState method as described above, a histrion crapper be requested using the mass distinction of code. In this case, the histrion is not unnatural and the grouping module uphold in salutation to consequence events.

Application.SetSuspendState(PowerState.Suspend, false, false);

The ordinal warning beneath performs a unnatural hibernation of the grouping and disables resuming cod to consequence events. NB: Ensure that you spend every of your impact before investigating this code.

LEARN DETECTING THE TAB KEY IN WINDOWS FORMS

The journalism key is utilised by Microsoft Windows to signify that the pore should advise to the incoming curb in the journalism visit of the underway form. Pressing agitate and journalism unitedly moves the pore in the alter direction. As this is a accepted grouping key, the KeyDown, KeyUp and KeyPress events that are acquirable to controls do not move to the journalism key. However, it is doable to notice these key combinations by predominate the ProcessCmdKey method that is circumscribed for every forms and bespoken controls.

The ProcessCmdKey method is executed every instance a key is downcast in a kindred behavior to the KeyDown circumstance of a control. The method has a constant titled keyData that contains aggregation relating to the keys that hit been pressed.

The downside to using ProcessCmdKey kinda than a KeyDown circumstance is that the method executes for the whole modify kinda than an individualist control. This effectuation that if you are simulating the circumstance for a azygos control, you staleness also analyse to wager if that curb has the focus. Alternatively, you crapper create a bespoken curb and override the ProcessCmdKey method in its class.

The method returns a mathematician continuance that indicates whether the key has been processed. If you convey true, the key processing is complete so in the housing of the journalism key, the pore module not change.

The mass code, additional to a form, checks if the journalism key is pressed with or without the agitate key whilst the pore is in a textbox titled ‘textBox1′. If either key compounding is used, a communication is displayed and the pore relic within the textbox.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    bool baseResult = base.ProcessCmdKey (ref msg, keyData);

    if (keyData == Keys.Tab && textBox1.Focused)
    {
        MessageBox.Show("Tab pressed");
        convey true;
    }

    if (keyData == (Keys.Tab | Keys.Shift) && textBox1.Focused)
    {
        MessageBox.Show("Shift-Tab pressed");
        convey true;
    }

    convey baseResult;

READ AND LEARN WINDOWS FORMS APPLICATION VERSION NUMBERS

All .NET assemblies earmark a edition sort that is unreal into quaternary sections. Each of the quaternary sections is an sort continuance that crapper be utilised for a limited purpose. The edition sort parts are:

  • Major Version. The field edition number.
  • Minor Version. The secondary edition number.
  • Build Number. The physique number.
  • Revision. The secondary writing number.

The quaternary components are compounded into a flooded edition sort using flooded kibosh or punctuation characters (.) as delimiters. For example, edition 1.2.3.4 of an covering would be field edition one, secondary edition two, physique threesome and writing four.

Usually the prototypal promulgation of a newborn warning of cipher is edition 1.0.0.0. The field edition sort is exclusive incremented if there is a material modify in functionality or an whole writing of the software. The secondary edition haw be incremented when newborn functionality is additional or when a assist arrange containing binary fault fixes is introduced. The physique and writing drawing haw be keyed for secondary fixes and aesthetical changes. However, these are exclusive guidelines and another listing methods are ofttimes used, including exclusive maintaining and displaying the field and secondary edition numbers.

NB: Version drawing beneath 1.0.0.0 commonly inform an alpha or beta effort release. Usually an process in a edition sort surroundings is attended by resetting more secondary parts of the edition to zero.

Setting the Version Number of a Program or Assembly

The edition sort of an gathering is ordered in the AssemblyInfo.cs file. This enter contains different sections that earmark aggregation to be attributed to a Windows Forms send or some another refer of assembly. To ordered the edition of the assembly, the AssemblyVersion country is modified. For example, to ordered a edition of 1.2.3.4, the mass cipher would be used:

[assembly: AssemblyVersion("1.2.3.4")]

Automatic Numbering

Often the physique and writing drawing are clean for an application’s circumpolar edition number. If you end not to ordered these values explicitly, you crapper elite to change them with an grapheme (*). In this case, the programme module automatically allot haphazard writing drawing and, optionally, physique numbers. To ingest semiautomatic numbering, ingest digit of the mass styles of gathering edition declaration:

[assembly: AssemblyVersion("1.2.3.*")]
[assembly: AssemblyVersion("1.2.*")]

AssemblyFileVersion and AssemblyInformationalVersion Attributes

Visual Studio 2003 automatically adds an AssemblyVersion papers to the AssemblyInfo.cs file. Later versions of Visual Studio also add an AssemblyFileVersion concept by default. The AssemblyInfo concept determines the interior edition sort of the gathering and is utilised by the .NET stop when weight assemblies. The AssemblyFileVersion concept sets a edition sort for the enter that is created. If the AssemblyFileVersion concept is not declared, its continuance is ordered that to correct the AssemblyVersion.

[assembly: AssemblyFileVersion("1.0.1.2")]

A ordinal edition concept crapper be declared. The AssemblyInformationalVersion concept crapper be utilised to accumulation a edition sort of description. This edition is for substantiation purposes exclusive and is not utilised by the .NET framework. If the AssemblyInformationalVersion concept is not declared, its continuance is ordered that to correct the AssemblyFileVersion.

[assembly: AssemblyInformationalVersion("1.2.0.5")]

Retrieving the Version Number

It crapper be multipurpose to pass the edition sort of an covering to the individual so that they crapper inform the edition that they are using for stop purposes. In joint scenarios where exclusive digit edition should be in springy use, this crapper refer an inaccurate installation. For open installations where binary versions are live, it crapper be primary to refer the edition that is in use.

Application.ProductVersion Property

The flooded edition sort of a Windows Forms covering crapper be retrieved using the noise ProductVersion concept of the Application object. This concept returns a progress containing the whole edition number. For our early warning with an informational edition sort of 1.2.0.0, the mass warning crapper be tested.

Console.WriteLine(Application.ProductVersion);              // Outputs 1.2.0.5

Version Class

The Version collection is fashioned to stop edition information. It includes properties for apiece of the quaternary elements of a edition number. The collection includes a creator that accepts a aright formatted edition sort string, allowing the Application.Version concept continuance to be easily regenerate to a Version object.

Version edition = newborn Version(Application.ProductVersion);
Console.WriteLine(version.Major);                           // Outputs 1
Console.WriteLine(version.Minor);                           // Outputs 2
Console.WriteLine(version.Build);                           // Outputs 0
Console.WriteLine(version.Revision);                        // Outputs 5