What is C#?
C# is the newest general purpose programming language from Microsoft. It stands on the shoulders of earlier programming language giants like C, C++, and Java. While C# came after Java, it is also considered a language ‘competing’ with Java for the hearts and minds of the developers.
First version of C# was released in mid-2000, while Java was developed and rose to prominence in early 90s. Significant features have been added to both these programming languages since their first releases.
While Microsoft originated C# and is its chief implementer, the language itself is standardized with standards organizations ECMA (European Computer Manufacturers Association) and ISO (International Standards Organization). The latest official C# language specification is Standard ECMA-334 C# Language Specification 4th Edition (June 2006). This document is available for free at ECMA web site (http://www.ecma-international.org/publications/standards/Ecma-334.htm).
Relationship with .Net Framework
While C# is a full-fledged, general-purpose programming language, it must be considered in conjunction with the .Net Framework (.Net platform, .Net environment, or simply .Net).
Figure 1. Relationship between C# and .Net Framework.
As shown in Figure 1, the .Net Framework consists of two major parts – a runtime environment called Common Language Runtime (CLR) and a class library called Framework Class Library (FCL). The runtime environment is a virtual machine (an idea similar to the Java Virtual Machine).
Here, the C# compiler takes the C# code you developed and converts into a language understood by the CLR. The language understood by the CLR is called Microsoft Intermediate Language (MSIL). In developing your C# programs, you would rely upon the vast functionality available with FCL.
The Development Tool for C#
The programs written in C# contain just a bunch of text (series of characters). So, strictly speaking, you would be able to develop C# programs using any text editor, including Notepad. However, developing any decent sized programs with a generic editor would be very painful.
The most powerful Integrated Development Environment (IDE) for developing C# programs is Visual Studio. A program that combines a powerful code editor, a built-in debugger, and GUI based features that ease the program development are called IDEs.
Figure 2. Developing a C# program with Visual Studio
Figure 2 shows the main window of Visual Studio with a Windows Forms program under development. Just to name a few features of Visual Studio:
- You can visually organize code files into projects and solutions
- As shown in Figure 2, you can draw the user interface using the tools in the toolbox and the necessary code is generated by the Visual Studio
- Figure 3 shows a powerful Code Editor. This editor features syntax highlighting (keywords are shown in one color, comments in another, etc.), Intellisense (as you type in code, the editor provides you help intelligently), XML Comments (The comments that start with ///; they can be used to generate documentation)
- The Community menu lets you post questions and search for the topics of interest
- The Servers tab provides a way to connect to the databases and do some database development
- Menus and toolbars visually provide a vast set of functionality to aid development, debugging, testing, building, and profiling
Figure 3. The powerful code editor in Visual Studio
Visual Studio comes in several flavors. The high-end Visual Studio Team System costs several thousand dollars; and the low-end Visual Studio Express is free. Even with the Visual Studio Express, you can do amazing amount of development. You can get more information about these products here: http://msdn2.microsoft.com/en-us/express/default.aspx
What kind of programs can be developed with C#?
Just like Java (and other recent programming languages), C# is highly buzzword-enabled. Let’s look at some important uses of C#. Using C#, you can develop programs for Windows, Web, and mobile devices.
The .Net Framework based windows development is branded as Windows Forms. These are the programs that run on Windows XP and Windows Vista. The client side programs developed this way are called Thick Clients or Smart Clients.
Using C# and .Net Framework, you can also develop Windows Mobile applications. These programs run on devices like Palm Treo and HP iPAQ.
In all the above cases, you can develop database applications using C#. The database connectivity and interaction is very easy using .Net Framework and C#.
You can also develop applications for Microsoft Office. Finally, you can also develop this sub-category of applications that fall under web, called Web Services. These are web-based programs that don’t have user interface. You call a function from an Internet address with a required set of parameters and that function does the appropriate processing and returns the results in XML format.
What are some of the biggest advantages of C# over older programming languages?
Perhaps the biggest advantage of C# over related languages like C and C++ is the automatic memory management, also known as garbage collection. In C/C++, it is the programmer’s responsibility to deallocate the memory once the objects that are consuming it are no longer in use. In C# (and Java), the run-time automatically senses when an object has gone out of scope and returns that memory to the operating system.
C# is a clean, simple, and powerful language for doing .Net based development. You can develop .Net programs using C++ (a flavor called C++/CLI), but it is rather painful and unwieldy. You can also develop .Net programs with VB (a flavor called VB.Net), but it feels different from how you think a Basic program should feel like. Needless to say both C++ and VB (or C++/CLI and VB.Net) are there because they satisfy certain need and demand.
The default library for C# is the .Net Framework (or Framework Class Library), which comes with powerful classes for windows and web development. So, you can start developing powerful applications in C# with minimal effort.
C# comes with the modern object-oriented language features. They include generics, partial and static classes, iterators, anonymous methods, nullable types, and complete integration of database querying right into the language (called LINQ – Language Integrated Query).