Introduction

Have you just installed Visual Studio and are ready to begin your first program? Then this is the sample for you. This is a basic example of some basic functions in C# C++ VB or F#. These basic skills are necessary for complex C# VB C++ or F# programming.

Building the Sample

To run this you will need Visual Studio 2013 or Visual Studio 2013 Express installed. They can be downloaded here. To run it open the .sln file then hit f5.

Description

This sample solves the program by creating a small interface in which you can choose to compare two numbers, or solve a mathematical equation with them. This sample explains string variables and integer variables, if equal, greater than, less than, greater than or equal, less than or equal, and not equal statements, and the addition, subtraction, multiplication, and division of numbers. Then you can look at the code and see what has happened. The interface is a collection of radioboxes, asking for operation, textboxes, for the numbers, and a picturebox, to show the relationship between the two numbers.

This is a small example of what happens when you click the add radiobox.

C#Visual BasicC++F#
Edit|Remove
private void radioButton1_CheckedChanged(object sender, EventArgs e) 
{ 
    string x = this.textBox1.Text; 
    string y = this.textBox2.Text; 
    if (x == ""//See if x has no value 
    { 
        x = "0"//Set x to 0 
    } 
    if (y == ""//See if x has no value 
    { 
        y = "0"//Set y to 0 
    } 
    int x_number = Convert.ToInt32(x); //Converts the string x to a number then stores it in x_number 
    int y_number = Convert.ToInt32(y); 
    int random = x_number + y_number; //Sets the integer variable random to the value of x_number plus y_number 
    string random_string = Convert.ToString(random); //Converts the integer random to the string random_string 
    this.label3.Text = random_string; 
}

This is a picture of the C# interface

Source Code Files

       C#

        C++

        VB

        F#

 

More Information

For more information on this sample, please feel free to ask questions on the Q&A. Any feedback will be appreciated.