Chapter 3. C# Language Fundamentals

Chapter 1 demonstrates a very simple C# program that prints the text string “Hello World!” to the console screen and provides a line-by-line analysis of that program. However, even that simple program was complex enough that we had to skip some of the details. In this chapter, we’ll begin an in-depth exploration of the syntax and structure of the C# language. The syntax of a language is the order of the keywords, where you put semicolons, and so forth. The semantics are what you are expressing in the code, and how your code fits together. Syntax is trivial and unimportant, but because compilers are absolute sticklers for correct syntax, novice programmers pay a lot of attention to syntax until they are comfortable. Fortunately, Visual Studio 2008 makes managing syntax much easier so that you can focus on semantics, which are far more important.

In this chapter, we’ll introduce statements and expressions, the building blocks of any program. You’ll learn about variables and constants, which let you store values for use in your program. We’ll also begin an explanation of types, and we’ll take a look at strings, which you saw briefly in the Hello World program. This is all very basic stuff, but it’s the foundation you need to start getting fancy. Without variables, your applications can’t actually process any data. All variables need types, and variables are used in expressions. You’ll see how neatly this all fits together.

Get Learning C# 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.