C Sharp programming language
C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their .NET initiative. Microsoft based C# on C++ and the Java programming language. C# was designed to balance power (the C++ influence) with rapid development (the Visual BASIC and Java influences). The C# compiler itself is written in C++. The chief architect of C# is Anders Hejlsberg.
| Table of contents |
|
2 Code libraries 3 Standardization 4 Example 5 Marketing 6 See also 7 External links |
C# does not compile to binary code which can be executed directly by the target computer. Instead, it is compiled to an intermediate representation. This form consists of metadata and instructions based upon a stack-based virtual machine. All .NET languages (which includes Visual Basic .NET, Managed C++, Delphi 8.Net as well as C#) compile to this intermediary code called Microsoft Intermediate Language (MSIL). To the casual observer the resulting program looks like a normal executable and has an ".exe" extension (on Microsoft Windows implementations) just like a normal application (code libraries have the standard ".dll" extension). However, executing the program fails on a computer that does not have an implementation of the .NET Framework installed.
When the program is executed, the .NET CLR (Common Language Runtime) compiles the intermediate code into binary code as it is run—just-in-time compilation (JIT). The resulting binary code is stored temporarily (in a memory cache), so if the program uses that portion of code again, the cached version is used. However this is only in effect during the runtime of the program. If a .NET application is run again, this compilation process is done again. The performance of a .NET program can be improved by precompiling the intermediate code to native code using a native code generator utility, but the .NET framework must still be installed for execution.
In addition to compiling intermediate code at runtime, the CLR provides other services. Security is built into the CLR so that programs from a low trust source can still be run but with limited permissions. Remoting allows a program to execute code on a different computer over a network. Because code from all .NET languages is compiled to an intermediate language, code written in different .NET languages can interoperate with no loss in performance.
The .NET Framework is a class library which can be used from a .NET language to perform tasks from simple data representation and string manipulation to generating dynamic web pages (ASP .NET), XML parsing and reflection (dynamic program compilation and inspecting other programs). The code is organised into a set of namespaces which group together classes with a similar function, e.g. System.Drawing for graphics, System.Collections for data structures and System.Windows.Forms for the Windows Forms system.
A further level of organisation is provided by the concept of an "Assembly." An Assembly is a single file which may contain many namespaces and objects. Programs needing classes to perform a particular function might reference assemblies such as System.Drawing.dll and System.Windows.Forms.dll as well as the core library (know as mscorlib.dll in Microsoft's implementation).
Microsoft has submitted C# to the ECMA for formal standardization. In December 2001, ECMA released ECMA-334 C# Language Specification. C# became an ISO standard in 2003 (ISO/IEC 23270). There are independent implementations being worked on, including:
Program execution
Code libraries
Standardization
More recently, Microsoft has announced plans to add support for generics (similar to C++ templates), partial types and some other new features. Those additions were already proposed for ECMA/ISO standardization.Example
using System;
namespace Example
{
public sealed class HelloWorld
{
string myString;
public string Value
{
get
{
return myString;
}
set
{
if(value == null)
throw new ArgumentNullException();
else
myString = value;
}
}
public HelloWorld()
{
myString = "Hello, world!";
}
public override String ToString()
{
return myString;
}
public static void Main()
{
HelloWorld myHelloWorld = new HelloWorld();
Console.WriteLine(myHelloWorld.ToString());
Console.WriteLine(myHelloWorld.Value);
Console.WriteLine(myHelloWorld);
myHelloWorld.Value = "Blah.";
Console.WriteLine(myHelloWorld.ToString());
Console.WriteLine(myHelloWorld.Value);
Console.WriteLine(myHelloWorld);
}
//Output is:
//Hello, world!
//Hello, world!
//Hello, world!
//Blah.
//Blah.
//Blah.
}
}
Marketing
Microsoft is aggressively marketing C# as well as the other .NET languages. For example, purchasers of the latest version of Visual Studio .NET (Microsoft's popular IDE) can immediately develop mobile device applications in C#. To develop mobile device applications in other languages, such as C++ (which Visual Studio supports), developers have to download a separate IDE which does not integrate with Visual Studio. With these barriers, Microsoft is motivating developers to abandon C++ and switch to C#.See also
External links
Programming languages
Ada | Algol | APL | BASIC | C | C++ | C# | Cg | COBOL | Common Lisp | ColdFusion | Delphi | Eiffel | Forth | FORTRAN | Haskell | Java | JavaScript | Jython | Lisp | Logo | Mesa | ML | Modula-2 | Oberon | Objective-C | Objective Caml | Pascal | Perl | PHP | PL/I | PostScript | Powerbuilder | Prolog | Python | QBASIC | REXX | Ruby | Scheme | Smalltalk | Tcl/Tk | Visual Basic