Tuesday, October 18, 2011

Writing a C# Program


Now that you ’ ve spent some time learning what C# is and how it fits into the .NET Framework,
it ’ s time to get your hands dirty and write some code. You use Visual Studio 2008 (VS) and Visual
C# 2008 Express Edition (VCE) throughout this book, so the first thing to do is have a look at some
of the basics of these development environments.
VS is an enormous and complicated product, and it can be daunting to first - time users, but using it
to create basic applications can be surprisingly simple. As you start to use VS in this chapter, you
will see that you don ’ t need to know a huge amount about it to start playing with C# code. Later in
the book you ’ ll see some of the more complicated operations that VS can perform, but for now a
basic working knowledge is all that is required.
VCE is far simpler for getting started, and in the early stages of this book all the examples are
described in the context of this IDE. However, if you choose to, you can use VS instead, and
everything will work in more or less the same way. For that reason, you ’ ll see both IDEs in this
chapter, starting with VS.
Once you ’ ve had a look at the IDEs, you put together two simple applications. You don ’ t need to
worry too much about the code in these for now; you just prove that things work. By working
through the application creation procedures in these early examples, they will become second
nature before too long.
The first application you create is a simple console application . Console applications are those that
don ’ t make use of the graphical windows environment, so you won ’ t have to worry about buttons,
menus, interaction with the mouse pointer, and so on. Instead, you run the application in a
command prompt window, and interact with it in a much simpler way.
The second application is a Windows Forms application . The look and feel of this is very familiar to
Windows users, and (surprisingly) the application doesn ’ t require much more effort to create.
However, the syntax of the code required is more complicated, even though in many cases you
don ’ t actually have to worry about details.