|
Introduction
What Is C#
Based on Microsoft, "C# is a modern, object-oriented language that enables programmers
to quickly build a wide range of applications for the new Microsoft .NET platform,
which provides tools and services that fully exploit both computing and communications."
My own definition will come after I know more about this language.
C# Programming Environment
The best environment to do C# programming at this time is Microsoft's .NET Framework SDK.
It is freely available from Microsoft Web site. You may follow the instructions bellow
download.NET Framework SDK:
1. Make sure you have Microsoft Windows 2000 with SP 2 applied.
2. Go to Internet at http://msdn.microsoft.com/netframework, and click "Download the .NET Framework".
3. Then click ".NET Framework SDK" to go to the download area.
4. Select the "Full SDK Download (131 MB)" next to the download icon.
5. Once the download is completed, double click the downloaded file in the File Exlorer.
And following the instructions on the screen to finish installing .Net Framework SDK on your system.
6. Restart your system, and open command window to enter "csc". If this command
returns with message:
>csc
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.
fatal error CS2008: No inputs specified
you know that you have .Net Framework SDK installed correctly.
7. If you don't see the above message, check to you have the following included in the command path:
C:\WINNT\Microsoft.NET\Framework\v1.0.3705
First Program in C#
Let's follow the tradition of the programming language world, and write our
first C# program to print out "Hello world!" on the screen.
You can use notepad to write the following code and save it as c:\home\herong\csharp\hello.cs:
class Hello {
public static void Main() {
System.Console.WriteLine("Hello world!");
}
}
To compile and run the program, open command window and issue the following commands:
>c:
>cd \home\herong\csharp
>csc hello.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.
>hello
Hello world!
Congratulation, you have successfully created, compiled, and executed your first C# program!
C# Program Structure
If you are Java programmer, you probably already noticed that our first C# program in the
previous section is about 90% indentical to the similar Hello program in Java. Both C# and
Java programs require at least one class in a program. Both of them also require an entry
point method called "public static void Main()" in the starting class. These requirements
are different than C++. In C++, the entry point is a function called "void main()", which
can not be part of any classes.
The 10% difference in the Hello program between C# and Java is at two places: one is the
argument list of the Main() method; the other is the method provided by the default library
to send output to the console screen.
Exercise: Modify the hello.cs to print the following message to the screen:
Hi There,
My name is X Y. I am enjoying this book.
|