Home > Articles > Programming > C#

  • Print
  • + Share This
This chapter is from the book

Understanding Punctuators

Before jumping into the different categories and specific operators within C#, it is important to understand about punctuators. Punctuators are a special form of operator that helps you format your code, do multiple operations at once, and simply signal information to the compiler. The punctuators that you need to know about are listed here:

  • Semicolon—The primary use of the semicolon is to end each C# statement. A semicolon is also used with a couple of the C# statements that control program flow. You will learn about the use of the semicolon with the control statements on Day 4, "Controlling Your Program's Flow."

  • Comma—The comma is used to stack multiple commands on the same line. You saw the comma in use on Day 2, "Understanding C# Programs," in a number of the examples. The most common time to use the comma is when declaring multiple variables of the same type:

  • int var1, var2, var3;
  • Parentheses, ()—Parentheses are used in multiple places. You will see later in today's lesson that you can use parentheses to force the order in which your code will execute. Additionally, parentheses are used with functions.

  • Braces, {}—Braces are used to group pieces of code. You have seen braces used to encompass classes in many of the examples. You also should have noticed that braces are always used in pairs.

Punctuators work the same way punctuation within a sentence works. For example, you end a sentence with a period or another form of punctuation. In C#, you end a "line" of code with a semicolon or other punctuator. The word line is in quotation marks because a line of code might actually take up multiple lines in a source listing. As you learned on Day 2, whitespace and new lines are ignored.

NOTE

You can also use braces within the routines that you create to block off code. The code put between two braces, along with the braces, is called a block.

  • + Share This
  • 🔖 Save To Your Account