Welcome to Sams Teach Yourself C# in 21 Days! In today’s lesson, you begin
the process of becoming a proficient C# programmer. Today you…
• Learn why C# is a great programming language to use.
• Discover the steps in the program-development cycle.
• Understand how to write, compile, and run your first C# program.
• Explore error messages generated by the compiler and linker.
• Review the types of solutions that can be created with C#.
• Create your first console and Windows forms program.
• Learn about object-oriented concepts.


What Is C#?

It would be unusual if you bought this book without knowing what C# is.
However, it would not be unusual if you didn’t know a lot about the language.
Released to the public as a beta in June 2000 and officially released in the
spring of 2002, C#—pronounced “see sharp”—has not been around for very
long.
C# is a language that was created by Microsoft and submitted to ECMA for standardization.
Its creators were a team of people at Microsoft that included the guidance of Anders
Hejlsberg. Interestingly, Hejlsberg is a Microsoft Distinguished Engineer who has created
other products and languages, including Borland Turbo C++ and Borland Delphi.
With C#, he and the team at Microsoft focused on using what was right about existing
languages and adding improvements to make something better.
Although C# was created by Microsoft, it is not limited to just Microsoft platforms. C#
compilers exist for FreeBSD, Linux, the Macintosh, and several of the Microsoft platforms.
C# is a powerful and flexible programming language. Like all programming languages, it
can be used to create a variety of applications. The C# language does not place constraints
on what you can do; therefore, your potential with it is limited only by your
imagination. C# has already been used for projects as diverse as dynamic Web sites,
development tools, and even compilers.
In the following section, you learn a process for creating and running a C# program. This
is followed by some additional background information on the C# language.

Preparing to Program


You should take certain steps when solving a problem. First, you must define the problem.
If you don’t know what the problem is, you will never find the solution. After you
know what the problem is, you can devise a plan to fix it. When you have a plan, you
can usually implement it. After the plan is implemented, you must test the results to see
whether the problem actually has been solved. This same logic can be applied to many
other areas, including programming.
When creating a program in C# (or in any language), you should follow a similar
sequence of steps:
1. Determine the objective(s) of the program.
2. Determine the methods you want to use in writing the program.
3. Create the program to solve the problem.
4. Run the program to see the results.
An example of an objective (see Step 1) is to write a word processor or database program.
A much simpler objective is to display your name on the screen. If you don’t have
an objective, you won’t be able to write an effective program.
The second step is to determine the method you want to use to write the program. Do
you need a computer program to solve the problem? What information must be tracked?
What formulas will be used? During this step, you should try to determine what you
need and in what order the solution should be implemented.
As an example, assume that someone asks you to write a program to determine the area
inside a circle. Step 1 is complete because you know your objective: Determine the area
inside a circle. Step 2 is to determine what you need to know to calculate the area. In this
example, assume that the user of the program will provide the radius of the circle.
Knowing this, you can apply the formula πr2 to obtain the answer. Now you have the
pieces you need, so you can continue to Steps 3 and 4, which are called the programdevelopment
cycle.

The Program-Development Cycle

The program-development cycle has its own steps. In the first step, you use an editor to
create a file that contains your source code. In the second step, you compile the source
code to create an intermediate file called either an executable file or a library file. The
third step is to run the program to see whether it works as originally planned.

Creating the Source Code

Source code is a series of statements or commands used to instruct the computer
to perform your desired tasks. These statements and commands are a set of keywords
that have special meaning along with other text. As a whole, this text is readable
and understandable.
As mentioned, the first step in the program-development cycle is to enter source code
into an editor. For example, here is a snippet of C# source code:
System.Console.WriteLine(“Hello, Mom!”);
This single line of source code instructs the computer to display the message Hello, Mom!
on the screen. Even without knowing how to program, you could speculate that this line
of source code writes a line (WriteLine) to the system’s console window (System.Console).
It is also easy to understand that the line written will be Hello Mom!.

Using an Editor

An editor is a program that can be used to enter and save source code. A number
of editors can be used with C#. Some are made specifically for C#, and others
are not.
Microsoft has added C# capabilities to Microsoft Visual Studio .NET, which now
includes Microsoft Visual C# .NET. This is the most prominent editor available for C#
programming; however, you don’t need Visual Studio .NET or Visual C# .NET to create
C# programs.
Other editors also are 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. Most of these
editors also provide features such as color-coding the text that you enter. This makes it
much easier to find possible mistakes. Many editors even give you information on what
you need to enter and by providing 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. If you’re using a Linux or UNIX system, you can use such
editors as ed, ex, edit, emacs, or vi.
The editor SharpDevelop is included on the CD with this book. For more on this editor,
see Appendix D, “Using SharpDevelop.”
Word processors can also be used to enter C# source code. Most word processors use
special codes to format their documents. Other programs can’t read these codes correctly.
Many word processors—such as WordPerfect, Microsoft Word, and WordPad—are capable
of saving source files in a text-based form. When you want to save a word processor
file as a text file, select the Text option when saving.

Naming Your Source Files


When you save a source file, you must give it a name. The name should describe what
the program does. Although you could give your source file any extension, .cs is recognized
as the appropriate extension to use for a C# program source file.
Posted by Unknown On Saturday, February 02, 2013 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Like us

    as

    Contact Form

    Name

    Email *

    Message *