Saturday 6 August 2011

Variables,Input,Output Statments

if you haven't read my previous tutorial go ahead and read it first. Simple c# programming Tutorial.

We can declare variables with the following datatype int,float,decimal,string,long,bool.
take a look at the following syntax.











In this case I've declared a variable a with datatype int.Which means "a" can have numbers like 12,2,5,6
but not numbers like 2.5,3.5 etc.

For that we've to declare a float or decimal variable.Variable  name can be anything in this case it is "a".
So my above code will output 5 on the black screen.

We can take input from the user also take a look at this





In this example I have converted an integer(int) variable and taken it input.After that I've outputted the value
on the screen which is taken input.
We can perform math functions also.like adding,subtracting etc.


This time I've used a more specific picture to point out the main lines which you've to change in the code.
I've tried to show you how many ways we can deal with declaring variables,inputing and outputing variables on the screen.
I've declare three variables a,b,c "a" contains null.
When a variable has no value stored in it.Then it contains null.
I've declared "b" with 8 and "c" also contains null.
Then when the code will reach line a=5; then the value 5 will be swaped in place of null for the variable "a".
Same procedure will happen for "c".
When the line reaches c=a+b then the sum of a and b will be stored in "c".If "c" would have been a string like
"name" which I've declared above than the compiler will give an error.Because a number and a string can't be added.You can concatinate two string but cannot add two string by concatination I mean join.Like if
a string variable contain "my name" and another one contain " is muazilla" then when you concatinate using the addition sign it will give you "my name is muazilla".Ok back to where I was.

so "c" will contain the value 13 because of a+b written on right side of it.Now in the end I've used a=a*2
which means overwrite the value of "a" by a value which is multiplied by "a" twice.So after this line "a" will contain the value 10 instead of 5.The output of the above image will be

That's it for this tutorial.You can leave comments for anything you want to ask or any kind of confusion.