Sams Teach Yourself C in 21 Days

(singke) #1
The C# Programming Language 771

BD7


available. If you don’t have Visual Studio .NET, however, you can still do C#
programming.
There are also other editors available for C#. Like Visual Studio .NET, many of these
enable you to do all the steps of the development cycle without leaving the editor. More
importantly, most of these color-code the text you enter. This makes it much easier to
find possible mistakes. Many editors will even help you by given you information on
what you need to enter and giving you a robust help system.
If you don’t have a C# editor, don’t fret. Most computer systems include a program that
can be used as an editor. If you’re using Microsoft Windows, you can use either Notepad
or WordPad as your editor.
As you will learn later, unlike C, C++, and Java, a C# compiler is available free of
charge. Because of this, you can start programming C# programs without spending
any money!

Naming Your Source Files

Although not explicitly stated, you have seen that C programs tend to have a .c exten-
sion. C++ programs generally have a .cpp extension. Java programs have a .java exten-
sion. For your C# programs, you’ll want to include a .cs extension. Although you could
give your source file any name and extension, .cs is recognized as the appropriate
extension to use.

Executing a C# Program

It is important to understand a little bit about how a C# program executes. C# programs
are different from programs you could create with other programming languages.
C# programs are created to run on the Common Language Runtime (CLR). This means
that if you create a C# executable program and try to run it on a machine that doesn’t
have the CLR or a compatible runtime, it won’t execute.
The benefit of creating programs for a runtime environment is portability. In languages
such as C and C++, if you wanted to create a program that could run on different plat-
forms or operating systems, you had to compile different executable programs. For
example, if you wrote a C application and you wanted to run it on a Linux machine and
a Windows machine, you would have to create two executable programs—one on a
Linux machine and one on a Windows machine. With C#, you create only one executable
program, and it runs on either machine.
If you want your program to execute as fast as possible, you want to create a true
executable. With programs such as C and C++, the compiler creates a file that
can be executed with no further effort.

NEWTERM

42 448201x-Bonus7 8/13/02 11:24 AM Page 771

Free download pdf