C# (pronounced as C sharp) is a new object oriented language, but will
certainly not be Latin and Greek to you. It is derived by the two very familiar
programming languages, C and C++. Both environments produce code that requires
just-in-time compiling immediately prior to execution. And like the Java Virtual
Machine (JVM), the C# run-time environment also abstracts the hardware.
The language will be ideal for developers building a wide range of
high-performance Web applications and components -- from XML-based Web services
to middle-tier business objects and system-level applications. The language may
help developers in accomplishing their tasks in fewer lines of code with fewer
opportunities for error. It is used to build Web services that can be used
across the Internet -- from any language on any platform. While offering
enhanced productivity, C# also enables complete access to the underlying
platform, as well as low-level code control, enabling the building of complex
business systems.
C# is shipped along with the Microsoft Visual Studio 7.0. In addition to C#,
Visual Studio supports Visual Basic, Visual C++, and the scripting languages
VBScript and JScript. All of these languages provide access to the .NET
platform, which includes a common execution engine and a class library. The .NET
platform defines a "Common Language Subset" (CLS), a sort of lingua
franca that ensures interoperability between CLS-compliant languages and class
libraries. For C# developers, this means that even though C# is a new language,
it has complete access to the same class libraries that are used by seasoned
tools such as Visual Basic and Visual C++. C# itself does not include a class
library.
Apps written in C# are deployed by .NET servers, which currently are limited to
Windows server platforms. Developers using C# will create the code in a
so-called intermediary language (IL). Analogous to Java byte code, ILs must be
compiled before execution. As with Java applets and the JVM, a CLR (Common
Language Runtime) must be present for an IL to run. Execution can take place
locally or on a server and delivered as browser content. As of now, CLRs will be
available only for Windows platforms.
To give you a peek into how the language looks, here is a simple "Hi
there" example for you:
using system;
class Hi
{
static void Main() {
Console.WriteLine("Hi, there");}
}
The source code for a C# program is typically stored in one or more text
files with a file extension of .cs, as in hello.cs
To compile the program, you can write a command line directive like
csc Hi.cs
which produces an executable program named Hi.exe. The output of the program
is:
Hi, there
The "using system;" is a directive that references a namespace
called system which is provided by the .NET class library. This namespace
contains the "console" class referred to in the "main"
method. Namespaces provide a hierarchical means of organizing the elements of a
class library.
The "main" method is the member of the class Hi. It is a static
modifier, hence it acts as a method on the class Hi rather than on instances of
the class. The premier entry point of the program is always a static method
called "main" which is a method called to begin execution. The
"Hi, there" is produced through the use of class library. The language
by its own does not provide a class library as we said before. Instead, it uses
a common class library that is also used by languages such as Visual Basic and
Visual C++.
That’s about it for the "Hi world" program. Let's see a few of
the related characteristics concerning the language:
- The program does not use a global method for Main. Methods and variables
are not supported at the global level; such elements are always contained
within type declarations (e.g., class and struct declarations). - The program does not use either "::" or "->"
operators. - The separator "." is used only in compound names such as
Console.WriteLine. - The program does not use #include to import program text.
The language promises to enhance developer productivity and fewer programming
errors that can help reduce development costs. If you are interested in learning
more about the language you can download the Microsoft C# language
reference from the msdn site.