WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
In this article, we will examine all the essential utilities needed to begin C# programming. In the end, you will also learn how to write a simple C# program.
Basic Requirements to Start with .NET
First of all, let's once again welcome you to the world of this new programming language. We hope you have a basic idea about Object Oriented Programming languages because many languages such as Java and C++ have emerged in the past five years. However, there will be no difficulty in learning this language if you are a beginner because this article and the coming ones will explain all the concepts and features right from the beginning. Wherever required, I explain the features involved in C-Sharp by comparing them with Java. This will ensure smooth progress for experienced programmers. Let's discuss the basic requirements needed to begin C# programming.
- Windows 2000 Operating System or Later
- .NET Framework SDK
- Code Editors
Optional requirements include:
- Visual Studio .NET
- Third-Party Editors
A detailed explanation regarding each of these requirements is outlined below.
Windows 2000 Operating System or Later
As a first step, you need this operating system installed on your system. This operating system comes in two flavors—the Professional and Server editions. However, the Professional edition is the best choice for many users. Even though Windows 98 is suitable for C# programming, it's not possible to work any effective .NET-based, server-side programming on it. Hence, Windows 98 is not the best choice for C# programming.
.NET Framework Software Development Kit
This kit is required to compile and execute C# and other .NET programming languages; it uses a built-in command line compiler (csc.exe) and interpreter for the same. It can be downloaded as a 110 MB file from the Microsoft Web site. The SDK comes with various tools for building, deploying applications, sample code, and the required documentation. It also comes with all the necessary tools to build and deploy ASP.NET applications. The topic of code editors as outlined in requirement number 3 will be discussed later in this article. To know more about this kit, refer to the section "Related Links" at the end of this article.
Visual Studio .NET
You can also develop C# applications using Visual C# .NET, available with Visual Studio .NET. But this is an optional choice and it's up to you to decide whether or not to use it. This will help you to develop Windows-based applications easily and with limited effort because you don't have to devote too much time to designing the user interface with WinForms. The only work left for you to do is to write the coding appropriately, as per the .NET Standards. A forthcoming section of this article will explain third-party editors in detail. To know more details about Visual Studio .NET, refer to the section Related Links at the end of this article.
Installing the .NET Framework SDK
After downloading the SDK, locate the drive and folder where you have downloaded the file. Click on the file to begin installation. The following figures will show you the installation process. When you click on the file, you will see a dialog box as shown in Figure 1. Click Yes to proceed further.
Figure 1—.NET Framework Setup
The setup will begin extracting the required cab files as shown in Figure 2.
Figure 2—Extracting cab files
Sometimes, while extracting, the setup program will ask you to update the Windows installation. If you had done this before, it will not ask. If you haven't updated, click Yes to have the setup update your current installation. Windows will prompt you to restart the system. Click Yes to do so.
After doing the above process, the setup will show a series of dialog boxes to proceed with the installation. After displaying the initial screen, setup will show a license agreement box. Click on the I Agree radio button to move on to the folder selection box. You can either choose an existing folder or specify a new folder name. We recommend that you specify a new folder name. Setup will automatically create the folder for you. After this, you may have to select the options for Installation. The whole process is self-explanatory and may vary depending up on the versions. Finally, setup begins the Installation and it will also show you the balance of time left to complete the installation.
When the .NET Framework has been completely installed, you again have to restart your system. After that, you can start programming with C#. You should install optional components such as Microsoft Data Access Components 2.7 for developing ASP.NET applications. The last section of this article illustrates how to code a simple "Hello World" C# program.
About the Editors
Choosing an editor for coding the source code is a tedious task facing every programmer. There will be various types of editors brought out by different companies. They are elaborated below in detail.
Notepad is the best and most widely used editor among developers using .NET SDK. It comes with every edition of the Windows operating system and it's easy to use. Also, it does not require much investment.
Figure 3—Hello.cs in Notepad
However, it is not the most suitable editor because it does not support syntax coloring and highlighting, compilation and execution directly from the editor, code numbering, and so forth. But as you know, Notepad in Windows 2000 Professional supports the famous Ctrl+G shortcut for finding line numbers.
Visual C++ 6.0
Developers can use Visual C++ 6.0, included with Visual Studio 6.0. However, they should do some tweaking in the Registry before using it. It supports syntax colorings and other features such as finding line numbers (Ctrl+G). However, it is dangerous for a new user to make changes in the Registry. Hence, only advanced and experienced users should use Visual Studio 6.0 for developing C#. It's not possible to compile and execute the applications from the Visual C++ 6.0 environment. Hence, it is not of much use except for some of the features listed above.
Visual Studio .NET
Visual Studio .NET provides all the integrated tools and wizards for creating C# and other .NET-based language applications. It also supports features such as Intellisense, Dynamic help, and so on. Moreover, you can compile and execute your applications from the IDE itself. Hence, to experience the power of developing the .NET applications, you should try Visual Studio .NET. But be prepared to pay a huge sum for this wonderful stuff.
Many third-party editors are now available and can be downloaded from the Internet. One such editor is called the Antechninus C# Editor. It supports color-coding, compilation and execution from the IDE, project maintenance, and accessing the .NET Framework documentation by using its help menu, and so forth. It can be downloaded free of cost from http://www.c-point.com/download/csharped.zip. Moreover, the editor comes with built-in tutorials on C#; they can be accessed from the Help menu.
However, it is up to you to decide which editor to use. I recommend you to try one common editor and learn the language in full.
The "Hello C#" Program
A majority of developers learned programming by coding the "Hello World" program. But, for a change, we will see the "Hello C#" program. As mentioned in the previous section, you can use any editor to code the program. It's your preference as to which editor to use. Listing 1 shows the coding for our "Hello C#" program:
public static void Main()
Console.writeLine ("Hello C#");
After entering the above code in an editor, you have to perform the following steps:
- Save the file as Hello.cs. cs is an extension to indicate C-Sharp, as you would use .java for a Java source file. You have to supply this extension when saving your file; otherwise, the code will not compile correctly. The saved file will have the extension .cs.txt.
- Compile the code by giving the following command at the command prompt:
- If there are compile errors, you will be prompted accordingly. Otherwise, you will view a command prompt along with the copyright information, as shown in Figure 4.
Figure 4—Compilation and Execution of "Hello C#"
- As a final step, you have to execute the program to view the final output. For that purpose, you simply give a command at the command prompt. Refer to Figure 4. If everything goes well, you can view the message "Hello C#" as shown in Figure 4.
We will analyze the preceding program in detail in the article "C# Program and Its Intermediate Language."
- Microsoft .NET Framework SDK
- Download Link
- SDK on CD-ROM
- Visual Studio home page
- More about Microsoft products
About the Author
Anand Narayanaswamy works as a freelance Web/Software developer and technical writer. He runs and maintains learnxpress.com, and provides free technical support to users. His areas of interest include Web development, software development using Visual Basic, and in the design and preparation of coursewares, technical articles, and tutorials. He can be reached at email@example.com.