Sams Teach Yourself C in 21 Days

(singke) #1
Consider another example of printing in C#:
System.Console.Write(“Value 1 is {0} and value 2 is {1}”, 123, “Brad”);
This prints
Value 1 is 123 and value 2 is Brad
You should notice that unlike C, you also don’t need to worry about what types the para-
meters are. Although a number and a string were both printed, the parameters were iden-
tified in the same way. The language takes care of the rest. Like in C, there are modifiers
that can be used if you want to format or change the way data is presented.

776 Bonus Day 7

Like in C programming, counting in C# starts with zero, not one.
Note

There is another important thing to know about WriteLine()andWrite().
These methods are a part of the .NET Framework. The .NET Framework is
used with any of the .NET programming languages. This includes Visual Basic
.NET.

Note


C# and the Web

In addition to standard applications, you can also create Web applications using C#. It is
beyond the scope of this single day’s lesson to show you everything about C#; however,
Listing B7.4 illustrates the use of C# in a Web application. In this listing, C# is being
used with ASP.NET to create a simple “hello world” Web application. To run this appli-
cation, you will need a server that supports ASP.NET.

LISTINGB7.4 hello.aspx. A “hello world” ASP.NET application using C#
1: <script runat=”server” language=”C#”>
2: void doClick(object sender, EventArgs e) {
3: MyLabel.Text = “Hello, world! (C# ASP.NET in action!)”;
4: }
5: </script>
6: <html>
7: <head><title>Hello World C# ASP.NET App</title></head>
8: <body>
9: <P>C# Web application...</P>
10: <form runat=”server”>

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

Free download pdf