Publishing System Settings Logout Login Register
C# - A Basic Understanding
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on March 16th, 2010
3469 views
C#

Operators

There are a few basic math operators that you will use in almost every program you ever write. These are: +-*/ or , in writing, plus, minus, times and divide.

So how do you use them in your program? Let's find out.

Lets start with a variable:

int myNumber = 0;

So we have a variable with the number 0 in it. Now lets add 5 to it.

myNumber = myNumber + 5;
Console.WriteLine(myNumber);
Console.ReadLine();

Now when you run the program the number 5 will show on the screen. Was that simple or what? And it's the same for any of these operators.

But that looks a bit ugly doesn't it? Stating the variable twice. Here's a way of making it look better.

myNumber += 5

Now what we are saying is "take the variable myNumber and add 5 to it." Looks better doesn't it? Either way works and will remain up to you which method you prefer.

Displaying Multiple Variables

Ok so now we'll see how to display several variables at once.

Lets start with 3 strings

string myString1 = "Hello";
string myString2 = "World";
string space = " ";

Now look at how simple it is to display them together:

Console.WriteLine(myString1 + space + myString2);

That will output "Hello World"

But if you don't want to use a variable to hold the space then thats easy to do as well.

Console.WriteLine(myString1 + " " + myString2);

This will give us the exact same result while taking up less memory.

So finally in the next chapter we're going to see how to accept user input and use it in an output. So hop on over and I'll see you there.

Next Page
Pages: 1 2 3 4 5
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
chironic

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top