C-Sharp
C # | |
---|---|
Object-oriented programming language |
|
Basic data | |
Paradigms : | multiparadigmatic: structured , imperative , declarative , object-oriented , event- oriented , functional , generic , reflexive , parallel |
Publishing year: | 2001 |
Designer: | Hejlsberg is different |
Developer: | Microsoft |
Current version | 8.0 (September 23, 2019) |
Typing : | static , strong , explicit (optional: dynamic , duck , implicit ) |
Important implementations : | Visual C #, mono |
Standardizations: | ECMA -334 |
Influenced by: | C ++ , C , Java , Delphi, Modula-3 , Cω , Eiffel , F # , Haskell , Icon, J # , Visual J ++ , Object Pascal , Rust , ML , Visual Basic |
Affected: | Java , Vala , Cω , Swift , VB.NET |
Operating system : | all for which a CLI implementation exists (e.g. Microsoft's .NET Framework or Xamarins Mono ) |
https://docs.microsoft.com/de-de/dotnet/csharp/ |
C # ( English c sharp [ siːʃɑːp ]) is a type-safe , object-oriented general-purpose - programming language . The architect of the language was Anders Hejlsberg on behalf of Microsoft ; Mads Torgersen is currently the chief developer. The language itself is platform-independent , but was developed as part of the .NET strategy, is optimized for this and can usually be found in its context.
Historically, C # was developed almost exclusively for Windows . Thanks to Xamarin , it is now also possible to develop for macOS , iOS and Android . In addition, with .NET Core there is also official support for GNU / Linux and macOS.
Up to version 2, the language was registered as a standard at ECMA and ISO . As a result, extensive extensions of the language by Microsoft appeared on a regular basis. Thanks to the development of the reference compiler as open source (since 2014), community contributions are also possible.
concept
C # takes up concepts from the 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 ++ that are generally considered to be insecure, such as pointers , are only allowed in C # for so-called "insecure code" that is used in zones with restricted rights (e.g. programs that are executed from web pages ) will not be executed without the granting of extended rights.
As a .NET language, C # also has language support for attributes and delegates . Attributes allow information about a class , an object , or a method to be stored, which can be evaluated at runtime . This is also referred to as metadata . A delegate can refer to methods of a class. The concept represents a further development of function pointers , such as those found in the C programming language. However, the delegate has a fixed type (called the delegate type) that defines a concrete signature that is checked by the compiler. For the call, the delegate also contains the reference to the object belonging to the methods. A call to a delegate specifically calls a method to which an object pointer is passed implicitly as a parameter . In addition, delegates must be declared type-safe , which means that incompatibilities in the method signatures between the calling delegate and the method to be called are noticed during compilation .
Starting with version 2.0 of C # with .NET Framework was released 2.0, supports C # in addition to generic types (English generics ) and anonymous methods , generators and partial classes . Generic types, iterators and partial classes are part of the .NET Framework 2.0 and are therefore also available to other .NET programming languages such as Visual Basic .NET .
standardization
Microsoft, together with Hewlett-Packard and Intel , submitted C # for standardization to the standards organization Ecma International in August 2000 . In December 2001 the ECMA published the standard ECMA-334 C # Language Specification . In 2003, C # was standardized by the ISO (ISO / IEC 23270).
In June 2005, the ECMA approved the third version (C # 2.0) of the C # specifications and updated the previous standard ECMA-334. Then there were the partial classes, anonymous methods, nullable types and generics, which are similar to the C ++ templates . In July 2005 the ECMA handed over the standards and associated TRs to ISO / IEC JTC 1.
The ECMA specification 334 only covers the C # language. Programs written in C # usually use the .NET framework, which is partly described by other specifications and partly proprietary . Nevertheless, the C # language is in principle platform-independent . The Mono project initiated by Ximian (now Xamarin ) enables users of macOS or Unix , for example , to use C # for developments on their operating system.
Microsoft released the third version of C # with the .NET SDK 2.0 and Visual Studio 2005 in November 2005.
Microsoft made it clear that C #, like other .NET languages, is an important part of its software strategy for both internal and external use. The company takes an active role in marketing the language as part of its overall business strategy.
Versions
year | version | newly introduced language elements | |
---|---|---|---|
.NET | C # | ||
2002 | .NET 1.0 | C # 1.0 | |
2003 | .NET 1.1 | C # 1.2 | |
2005 | .NET 2.0 | C # 2.0 |
Generics |
2006 | .NET 3.0 | ||
2007 | .NET 3.5 | C # 3.0 |
Implicitly typed variables |
2010 | .NET 4.0 | C # 4.0 |
Dynamic binding |
2012 | .NET 4.5 | C # 5.0 |
Asynchronous methods |
2015 | .NET 4.6 | C # 6.0 |
Initializers for auto properties |
2017 | .NET 4.6.2 .NET Core |
C # 7.0..7.3 |
Declaration expressions on out parameters The Main method can be async |
2019 | .NET Core 3 | C # 8.0 | Standard implementations in interfaces
Switch expressions Index and range operators for addressing subsets asynchronous streams (asynchronous iteration with foreach) nullable reference types (e.g. string?) static local functions |
Integrated development environments (IDEs)
The dominant development platform is Microsoft Visual Studio ( Windows and macOS , proprietary software ). There are also a number of other development environments (IDEs) for C #, but the latest language standards and runtime environments ( .NET Core ) are not always supported:
- Visual Studio Code (Windows, macOS, and Linux )
- Baltie (Windows, proprietary) especially for children
- With ReSharper (Windows, proprietary), JetBrains offers a range of plug-ins for Visual Studio, which are intended to improve it
- Rider (Windows, Linux and Mac OS)
- MonoDevelop (GNU / Linux; FLOSS )
- Notepad ++ (Windows; FLOSS) with the CS-Script (FLOSS) plug -in enables auto-completion , code execution and debugging
- the OmniSharp project enables, facilitates and expands the possibilities of various popular editors ( Atom , Adobe Brackets , Emacs , Sublime Text , Vim and Visual Studio Code) with regard to C # (as part of .NET)
- SharpDevelop (Windows; FLOSS)
- Xamarin Studio (Windows and OS X)
Compiler
As a rule, the C # compilers do not translate directly into machine language, but into an intermediate language.
When it is executed, a virtual machine is started that does the second part of the translation process in a just-in-time compiler.
There are four compilers for C #:
- the Roslyn compiler ( Windows ; FLOSS ) developed by Microsoft for the latest versions of C # and Visual Basic .NET as the latest iteration of the .NET Compiler Platform (whose older versions were proprietary software )
- the one from Xamarin for Mono (Windows, macOS , GNU / Linux ; FLOSS)
- the set DotGNU (FLOSS)
- CoreRT / .Net Native
Naming
C # was developed under the code name Cool , but changed for marketing reasons for publication. The name C Sharp is derived from the symbol cross ( ♯ , English sharp ) in the musical notation , which stands for an increase in the fundamental tone by a semitone . C sharp is the English term for the tone c sharp . This is an allusion to the fact that the name of the programming language C ++ comes from the notation for increasing the value of a variable by one. Furthermore, the cross sign can be viewed as a combination of four plus signs, which is supposed to represent an increase in C ++. However, the name does not contain the cross symbol of the music notation, but a double cross or diamond , which is often used as a substitute for the cross, because it appears on conventional keyboards in contrast to the cross.
In artistic representations, the musical notation is sometimes used, which is considered correct by some in the following. The double use of the double dagger character is clearly wrong .
Language elements
C # syntax example for a simple command line program:
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine("Hallo Welt!");
}
}
Simple MessageBox in C #
using System;
using System.Windows.Forms;
class Program {
public static void Main() {
MessageBox
.Show("Text", "Titel", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
FileStream example in C #
using System;
using System.IO;
using System.Text;
class Program {
public static void Main() {
// Text, der in die Datei geschrieben wird
const string textToWrite = "Hallo Welt";
const string fileName = "dateiname.txt";
// Datei "dateiname.txt" wird erstellt oder überschrieben
using (var stream = new FileStream(fileName,
FileMode.Create,
FileAccess.Write)) {
// Der Text wird UTF8-kodiert in die Datei geschrieben
var data = Encoding.UTF8.GetBytes(textToWrite);
stream.Write(data, 0, data.Length);
// Datei wird geschlossen...
}
}
}
Networking example in C #
using System.Text;
using System.Net;
using System.Net.Sockets;
using static System.Console;
class Program {
public static void Main() {
// Daten, die gesendet werden
const string textToSend = "Hallo Welt";
// Endpunkt, zu dem verbunden wird
const string localhost = "127.0.0.1";
const int port = 80;
var data = Encoding.UTF8.GetBytes(textToSend);
var ip = IPAddress.Parse(localhost);
var ipEndPoint = new IPEndPoint(ip, port);
// Socket, das verwendet wird
using (var socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp)) {
// Es wird zum Endpunkt verbunden
socket.Connect(ipEndPoint);
// Daten werden gesendet
var byteCount = socket.Send(data, SocketFlags.None);
WriteLine("Es wurden {0} bytes gesendet", byteCount);
// Puffer für die zu empfangenen Daten
var buffer = new byte[256];
// Daten werden empfangen
byteCount = socket.Receive(buffer, SocketFlags.None);
// Wenn eine Antwort erhalten wurde, diese ausgeben
if (byteCount > 0) {
WriteLine("Es wurden {0} Bytes empfangen", byteCount);
var answer = Encoding.UTF8.GetString(buffer);
WriteLine("Empfangene Daten: {0}", answer);
}
// Verbindung wird geschlossen
}
}
}
Speech derivatives
- Cω
- eXtensible C # (XC #)
- Metaphor
- MMC #
- Multiprocessor C # (MC #)
- Polyphonic C #
- Sing #
- Spec #
- Vala for programs of the Gnome project
See also
literature
- Joseph Albahari; Ben Albahari: C # 6.0 in a Nutshell. The Definitive Reference . 6th edition. O'Reilly, Sebastopol 2016, ISBN 978-1-4919-2706-9 , pp. 1136 (English, table of contents , text of contents [PDF]).
- Joseph Albahari; Ben Albahari: C # 8.0 Pocket Reference: Instant Help for C # 8.0 Programmers . O'Reilly, Sebastopol 2019, ISBN 978-1-4920-5120-6 , pp. 240 (English, content text ).
- Walter Doberenz; Thomas Profitus: Visual C # 2015. Basics, professional knowledge and recipes . Hanser, Munich 2015, ISBN 978-3-446-44381-5 , pp. 1195 ( table of contents , text of contents ).
- Matthias Geirhos: Developing professionally with C # 6 and Visual Studio 2015. The practical book . 3rd, updated and expanded edition. Rheinwerk, Bonn 2016, ISBN 978-3-8362-3929-5 , p. 1209 ( table of contents , text of contents ).
- Jay Hilyard; Stephen Teilhet: C # 6.0 Cookbook. Solutions for C # Developers . 4th edition. O'Reilly, Sebastopol 2015, ISBN 978-1-4919-2146-3 , pp. 704 (English, table of contents , text of contents [PDF]).
- Andreas Kühnel: C # 8 with Visual Studio 2019: the comprehensive manual . 8th, updated edition. Rheinwerk, Bonn 2019, ISBN 978-3-8362-6458-7 , pp. 1478 ( table of contents , text of contents ).
- Mark Michaelis; Eric Lippert: Essential C # 7.0 . 6th edition. Addison-Wesley, New York a. a. 2018, ISBN 978-1-5093-0358-8 , pp. 1040 (English, content text ).
- Hanspeter Mössenböck: Compact course C # 7.0 . dpunkt, Heidelberg 2018, ISBN 978-3-86490-631-2 , p. 344 ( table of contents , text of contents [PDF]).
- John Sharp: Microsoft Visual C # Step by Step . 9th edition. Microsoft, Redmond 2018, ISBN 978-1-5093-0776-0 , pp. 832 (English, content text ).
- Thomas Theis: Getting started with C # with Visual Studio 2015. Ideal for programming beginners . 4th updated edition. Rheinwerk, Bonn 2015, ISBN 978-3-8362-3705-5 , pp. 553 ( table of contents , text of contents ).
- Bernhard Wurm: Schrödinger programs C #. The slightly different textbook . 3. Edition. Rheinwerk, Bonn 2019, ISBN 978-3-8362-6968-1 , p. 749 ( table of contents , text of contents ).
Individual evidence
- ^ Richard Lander: Announcing .NET Core 3.0 . September 23, 2019 (accessed October 28, 2019): " C # 8 is also part of this release "
- ↑ Java 5 catches up with C #
- ↑ So far see: Joseph Albahari; Ben Albahari: C # 6.0 in a Nutshell. The Definitive Reference . 6th edition. O'Reilly, Sebastopol 2016, ISBN 978-1-4919-2706-9 , pp. 1-6 . Joseph Albahari; Ben Albahari: C # 6.0 Pocket Reference Instant Help for C # 6.0 Programmers . O'Reilly, Sebastopol 2015, ISBN 978-1-4919-2741-0 , pp. 1 .
- ↑ Archived copy ( Memento of the original dated December 2, 2012 in the Internet Archive ) Info: The archive link has been inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.
- ↑ http://standards.iso.org/ittf/PubliclyAvailableStandards/c042926_ISO_IEC_23270_2006(E).zip
- ↑ https://github.com/dotnet/roslyn
- ↑ James Kovacs: C # /. NET History Lesson. September 7, 2007, accessed March 25, 2015 .
- ^ Naomi Hamilton: The AZ of Programming Languages: C #. Interview with Anders Hejlsberg. October 1, 2008, accessed March 23, 2015 .
- ↑ Standard ECMA-334 “C # Language Specification”. (PDF; 5.60 MB) Chapter 6 “Acronyms and abbreviations”. (No longer available online.) Ecma International, June 2006, archived from the original on December 2, 2012 ; accessed on March 23, 2015 (English). Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.
- ↑ Foreword to the book C # with Method , Christian Bleske (Eds.), Alexander Mayer, Michael Fischer, Michael Starke, Michael Steil ( PDF ( Memento of the original from February 1, 2012 in the Internet Archive ) Info: The archive link was automatically inserted and still not checked. Please check the original and archive link according to the instructions and then remove this note. )
- ↑ [1] , O.Lampl; L.Böszörmenyi; Adaptive quality-aware programming with declarative QoS constraints
Web links
- C # documentation at microsoft.com
- C # in the Mono project
- C # tutorial by Derek Banas on YouTube
- Introduction to programming with C # 7.3 from the Center for Information, Media and Communication Technology at the University of Trier
- Link catalog on the subject of C-Sharp at curlie.org (formerly DMOZ )