Introduced in 2002, C# (pronounced “C sharp”) is a pro-gramming language similar to C++ and Java but simplified in several respects and tailored for use with Microsoft’s latest programming platform (see Microsoft.net). C# is a general-purpose language and is thoroughly object-oriented—all functions must be declared as members of a class or “struct,” and even fundamental data types are derived from the System.Object class (see class and object-oriented programming).
Compared with C++, C# is stricter about the use and conversion of data types, not allowing most implicit con-versions (such as from an enumeration type to the cor-responding integer—see data structures). Unlike C++, C# does not permit multiple inheritance (where a type can be derived from two or more base types), thereby avoid-ing an added layer of complexity in class relationships in large software projects. (However, a similar effect can be obtained by declaring multiple “interfaces” or specified ways of accessing the same class.)
Unlike Java (but like C++), C# includes pointers (and a safer version called “delegates”), enumerations (enum types), structs (treated as lightweight classes), and over-loading (multiple definitions for operators). The latest ver-sion of the language, C# 3.0 (introduced in 2007), provides additional features for list processing and functional pro-gramming (see functional languages).
The canonical “Hello World” program looks like this in C#:
using System;
// A “Hello World!” program in C# namespace HelloWorld
{
class Hello
{
static void Main()
{
System.Console.WriteLine(“Hello World!”);
}
}
}
Essentially all program structures must be part of a class. The first statement brings in the System class, from which are derived basic interface methods. A program can have one or more namespaces, which are used to organize classes and other structures to avoid ambiguity. This pro-gram has only one class (Hello), which includes a Main function (every program must have one and only one). This function calls the Console member of the System class, and in turn uses the WriteLine method to display the text.
C++ and Microsoft Development
C# is part of a family of languages (including C++, J# [an equivalent version of Java], and Visual Basic.NET). All these languages compile to a common intermediate lan-guage (IL). The common class framework, Microsoft.NET, has replaced earlier frameworks for Windows program-
ming and, increasingly, for modern Web development (see also Ajax).
Although it has been primarily associated with Micro-soft development and Windows, the Mono and Dot GNU projects provide C# and an implementation of the Com-mon Language Infrastructure, and many (but not all) of the
.NET libraries for the Linux/UNIX environment.
No comments:
Post a Comment