Information Technology Reference
In-Depth Information
A Simple C# Program
This chapter will lay the groundwork for studying C#. Since code samples will be used exten-
sively throughout the text, you first need to see what a C# program looks like and what its
various parts mean.
I will start by demonstrating a simple program and explaining its components one by one.
This will introduce you to a range of topics, from the structure of a C# program to the method
of producing program output to the screen.
With these source code preliminaries under your belt, you can then use code samples
freely throughout the rest of the text. So, unlike the following chapters, where one or two topics
will be covered in detail, this chapter will touch on many topics with a minimum of
explanation.
Let's start by looking at a simple C# program. The complete program source is shown in
the top shaded area in Figure 2-1. As shown, the code is contained in a text file called
SimpleProgram.cs . As you read through it, don't worry about understanding all the details.
Table 2-1 gives a line-by-line description of the code.
￿
When the code is compiled and executed, it displays the string “Hi there!” in a window
on the screen.
￿
One line contains two contiguous slash characters. These characters—and everything
following them on the line—are ignored by the compiler. This is called a single-line
comment .
Figure 2-1. The SimpleProgram programn
Search WWH ::




Custom Search