Addition In C Sharp:
Step 5:
We want to add variable "a" in to variable "b" and save the result in c the addition syntax will
c = a + b;
Lets see addition in detail in simple steps.
Step 1:
Start a new Windows form application project.
Step 2:
Go to toolbox and add a button on your form.
Step 3:
Now double click on Button you added.
Step 4:
Now Create 3 variables and assign them values as under.
int a = 10;
int b = 20;
int c = 0;
Step 6:
if we want to add variable "a" , "b" and variable " c " and save the result in d the addition syntax will:
int d = a + b + c;
Step 7:
Now lets add some floats and doubles.
Addition of float and double variables uses the same method and syntax as integers.
float num_1 = 10;
float num_2 = 20;
float num_3 = 0;
to add num_1 to num_2 and save answer in num_3 type the following code.
num_3 = num_1 + num_2;
to add num_1 to num_2 and num_3 save answer in num_4 type the following code.
float num_4= num_1 + num_2 + num_3;
Step 8:
Now lets add some doubles or float and integers.
In cause adding floats or doubles to integers the results should be save in double or float variable.
let see the example.
double n1=3.525;
int z =10;
double m= z+ n1;
Step 9: lets out put via message box.
MessageBox.Show(z + " +
" + n1 +" = "+m);
This will show a message box as shown
Feel free to contact me at any time for any type of question regarding C sharp.

No comments:
Post a Comment