C Sharp (programming language)

C # ( c sharp read English, English pronunciation [ ˌ si ː ʃɑ ː p] ) is a technology developed by the software manufacturer Microsoft as part of its. NET strategy programming language. C # is registered as the default in ECMA and ISO.

The current version of C # 5.0 was released in 2012 simultaneously with the Microsoft. NET Framework 4.5.

Concept

C # draws on concepts of programming languages ​​Java, C , Haskell, C and Delphi. C # is one of the object-oriented programming languages ​​and supports both the development of language-independent. NET components and COM components for use with Win32 application programs.

Some of the elements of C , which is generally considered to be unsafe, such as pointers, in C # only allows for so-called "unsafe code" in zones with restricted rights (for example, in programs that are executed from within Web pages ) will not be executed without the allocation extended rights.

As a. NET language C # has language support for attributes and delegates. Attributes make it possible to store information about a class, a property, or a method that can be evaluated at run time. It is also called metadata. A delegate can refer to methods of a class. The concept can be compared with function pointers. In contrast to these delegates in addition also contain references to the objects belonging to the methods. A call to a delegate so calls to methods that implicitly an object pointer is passed as a parameter. In addition, delegates must be declared type safe, which has the consequence that the method signatures incompatibilities between the calling delegate and the method to be invoked are resolved already at compile time.

As of version 2.0 of C #, which was released with. NET Framework 2.0 supports C # besides generic types (English generics ) also collects anonymous methods, generators and partial classes. Generic types, iterators, and partial classes are part of. NET Frameworks 2.0 and are thus available to others. NET programming languages ​​such as Visual Basic. NET available.

Standardization

Microsoft submitted C # in August 2000 along with Hewlett -Packard and Intel in the standardization organization Ecma International for Standardization one. In December 2001, the ECMA published the Standard ECMA -334 C # Language Specification. 2003 C # by the ISO -standard ( ISO / IEC 23270 ).

In June 2005, ECMA approved the third version (C # 2.0 ), the C # specification, and updated the previous standard ECMA- 334. Added to this were the partial classes, anonymous methods, nullable types, and generics, which have similarities to the C templates. In July 2005, the ECMA standards and related TRs to ISO / IEC JTC 1 handed

The ECMA- 334 specification only covers the C # language. Programs that are written in C #, usually use the. NET Framework, which is partially described by other specifications and is partially proprietary. However, the C # language is in principle platform independent. The Ximian (now Xamarin ) initiated project Mono for example also permits users of Mac OS X or Unix, C # to use for developments in their operating system.

Microsoft released the third version of C # with. NET 2.0 and Visual Studio 2005 in November 2005.

Microsoft made ​​it clear that C #, as well as others. NET languages ​​constitutes an important part of its software strategy for both internal as well as external use. The company takes an active role in the marketing of the language as part of its overall business strategy.

C # versions

  • Generics
  • Partial Types
  • Anonymous Methods
  • Iterators
  • Nullable data type
  • Private setters
  • Delegates
  • Covariance and contravariance
  • Static Classes
  • Implicitly typed variables
  • Object and Collection initializers
  • Auto-Implemented Properties
  • Anonymous data types
  • Extension Methods
  • LINQ
  • Lambda Expressions
  • Expression Trees
  • Partial Methods
  • Dynamic Binding
  • Named and Optional Arguments
  • Generic co-and contravariance
  • Embedded Interop types of data ( " NoPIA " )
  • Asynchronous methods
  • Caller Info Attributes
  • Initializers for auto Properties
  • Primary constructors to classes and Structures
  • Import static functions in the namespace
  • Declaration expressions for local variables
  • Exception filter
  • Binärliterale and numeric separators
  • Indexed member variables and element initializers
  • Await in try -catch-finally block
  • Collection initializer use Add () Erweiterunsmethode

Availability of integrated development environments

In addition to the products sold by Microsoft development platform Microsoft Visual Studio and the limited in their range of features, the free version Microsoft Visual Studio C # Express, there are now also development environments ( IDEs) from other manufacturers for C #:

  • Baltie, C # IDE for Children
  • C # Builder, Borland ( Uses the Microsoft C # compiler under license)
  • MonoDevelop - IDE for Windows and Unix -based operating systems ( open source )
  • SharpDevelop - ( open-source )
  • XNA Game Studio - IDE from Microsoft for game development

Compiler

  • The open- source project developed a free dotgnu. NET version includes C # compiler and support for Windows Forms, has now been set, however.
  • The open- source project Mono developed a free and platform-independent. NET version includes C # compiler.

Naming

C ♯ is originally a symbol of the music by a cross ( ♯ ) increased by a half tone C, the C sharp - English C sharp. Since the cross, however, can be entered directly on any standard keyboard is selected in the spelling of the name is usually the typographically similar # sign as a substitute representation.

Language elements

C # syntax example of a simple command line program:

Using System.Console; / / From C # 6   private class Program {    public static void Main ()    {      WriteLine ( "Hello World! ");    } } Simple MessageBox in C #

Using System; using System.Windows.Forms;   private class Program {    public static void Main ()    {      MessageBox.Show ("Text", "Title", MessageBoxButtons.OK, MessageBoxIcon.Hand );    } } FileStream example in C #

Using System; using System.IO; using System.Text;   private class Program {    public static void Main ()    {      / / Text to be written to the file      const string textToWrite = " Hello World";      const string filename = " filename.txt ";        / / File " filename.txt " is created or overwritten      using ( var stream = new FileStream (filename, FileMode.Create, FileAccess.Write ) )      {         / / The text is written to the file UTF8 encoded         var data = Encoding.UTF8.GetBytes ( textToWrite );         stream.Write (data, 0, data.Length );         / / File is closed ..      }    } } Networking example in C #

Using System.Console; using System.Text; using System.Net; using System.Net.Sockets;   private class Program {    public static void Main ()    {      const string textToSend = " Hello World"; / / Data that are sent      const string localhost = " 127.0.0.1 "; / / Endpoint is connected to the      const int port = 80;        var data = Encoding.UTF8.GetBytes ( textToSend );      var ip = IPAddress.Parse (localhost );      var = new IPEndPoint IPEndPoint (ip, port);        / / Socket, is used      using ( var socket = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) )      {        Socket.connect ( IPEndPoint ); / / It is connected to the end point        var = byteCount Socket.Send (data, SocketFlags.None ); / / Data to be sent        WriteLine ( " There are { 0} bytes sent ", byteCount );        var buffer = new byte; / / Buffer for the data to be received        byteCount = socket.Receive (buffer, SocketFlags.None ); / / Data is received          / / If a response was obtained, this issue        if ( byteCount > 0)        {            WriteLine ( " There are { 0} bytes recieved " byteCount );            var answer = Encoding.UTF8.GetString (buffer );            WriteLine ( " Received data: {0 }", answer);        }          / / Connection is closed.      }    } } language derivatives

  • Metaphor
  • MMC #
  • Multiprocessor C # ( MC # )
  • Polyphonic C #
  • Sing #
  • Spec #
  • Vala programs for the Gnome project
157778
de