Sams Teach Yourself C in 21 Days

(singke) #1
form. Lines 10, 11, and 14 contain an extra ASP.NET command—runat=”server”.
Otherwise, this is straight HTML. C# is used in lines 1 to 4 within an ASP.NET script.
This script is called when the button on the form is clicked. As you can see, the script
identifies the language as C# in line 1. In line 3 all the work is done. A line of text is
assigned to the label on the form.
This is not complex C# code; however, it could be. Instead of simply assigning a value to
a label, you could do any C# programming you need to do for your program. The idea
here was to show how simple it is to start using C# with a Web application.

Summary

At the beginning of today’s lesson you learned what C# has to offer, including its power,
its flexibility, and its object orientation. You also learned that C# is considered simple
and modern.
Today you explored the various steps involved in writing a C# program. You also took a
quick look at a simple C# application. You followed this by getting a closer look at how
C# can display information with Write()andWriteLine(). Overall you should have
noticed that a lot of the C# syntax comes from C.
The last section of today’s lesson took you to the Web. You saw a simple “hello world”
application that used C# with ASP.NET.

Q&A

Q If I wanted to learn C#, what would be a good book?
AIf you have enjoyed this book, you should also enjoy Sams Teach Yourself C# in 21
Days(ISBN 0-672-32071-1).
Q Will a C# program run on any machine?
ANo. A C# program will run only on machines that have the Common Language
Runtime (CLR) installed. If you copy the executable program to a machine that
does not contain the CLR, you get an error. On versions of Windows without the
CLR, you usually are told that a DLL file is missing.
Q If I want to give people a program I wrote, which files do I need to give them?
AOne of the nice things about C# is that it is a compiled language. This means that
after the source code is compiled, you have an executable program. If you want to
give the hello program to all your friends with computers, you can. You give them
the executable program, hello.exe. They don’t need the source file, hello.cs, and
they don’t need to own a C# compiler. They do need to use a computer system that
has a C# runtime, such as the Common Language Runtime from Microsoft.

778 Bonus Day 7

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

Free download pdf