If you wanted to add 1 to a variable, you could use the + operator:
count = count + 1;
However, it is unlikely that an experienced programmer would write code like this. Adding 1 to a variable is so common that in C#, you can do it with the ++ operator. To increment the variable count by 1, write the following statement:
count++;
Similarly, subtracting 1 from a variable is so common that in C# you can do it with the –– operator. To decrement the variable count by one, write this statement:
count--;
The following table shows you how to use these two operators.
Don't write this |
Write this |
variable = variable + 1; |
variable++; |
variable = variable - 1; |
variable--; |
If you want to continue to the next chapter
Keep Visual Studio 2005 running, and turn to Chapter 3.
If you want to exit Visual Studio 2005 now
On the File menu, click Exit. If you see a Save dialog box, click Yes to save your work.