C-Sharp

from Wikipedia, the free encyclopedia
C #
C Sharp wordmark.svg
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 , , Eiffel , F # , Haskell , Icon, J # , Visual J ++ , Object Pascal , Rust , ML , Visual Basic
Affected: Java , Vala , , 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

C # 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
Partial types
Anonymous methods
Iterators Nullable
data type
Private setters
Delegates
Covariance and contravariance
Static classes

2006 .NET 3.0
2007 .NET 3.5 C # 3.0

Implicitly typed variables
Object and collection initializers
Automatically implemented properties
Anonymous data types
Extension methods
LINQ
Lambda expressions
Expression trees
Partial methods

2010 .NET 4.0 C # 4.0

Dynamic binding
Named and optional arguments
Generic co- and contravariance
Embedded Interop data types ("NoPIA")

2012 .NET 4.5 C # 5.0

Asynchronous methods
caller info attributes

2015 .NET 4.6 C # 6.0

Initializers for auto properties
Import of static functions into the namespace
Exception Filters
Indexed member variables and element initializers
The keyword awaitin try- catch- Use finallyBlocks
Collection initializers Add () - Extension
method
String interpolation Multi-line string expressions
Null conditional operator
nameofexpression
Implementation of methods using Lambda -Expression

2017 .NET 4.6.2
.NET Core
C # 7.0..7.3

Declaration expressions on out parameters
pattern matching (pattern matching)
isexpressions with patterns
switchstatements with type patterns and additional conditions
tuple
deconstruction of tuples
declared local features
padding _to improve readability of numbers
Binärliterale 0b...
references (links) as the return value of functions and local variables
Generalized async return types

The Main method can be async
Lambda expressions =>in constructors, accessors ( get, set) and finalizers.
Exceptions within expressions produce
conditional refexpressions

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:

  • 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 #:

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

See also

literature

Individual evidence

  1. ^ Richard Lander: Announcing .NET Core 3.0 . September 23, 2019 (accessed October 28, 2019): " C # 8 is also part of this release "
  2. Java 5 catches up with C #
  3. ↑ 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 .
  4. 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. @1@ 2Template: Webachiv / IABot / www.ecma-international.org
  5. http://standards.iso.org/ittf/PubliclyAvailableStandards/c042926_ISO_IEC_23270_2006(E).zip
  6. https://github.com/dotnet/roslyn
  7. James Kovacs: C # /. NET History Lesson. September 7, 2007, accessed March 25, 2015 .
  8. ^ Naomi Hamilton: The AZ of Programming Languages: C #. Interview with Anders Hejlsberg. October 1, 2008, accessed March 23, 2015 .
  9. 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. @1@ 2Template: Webachiv / IABot / www.ecma-international.org
  10. 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@ 2Template: Webachiv / IABot / www.cul.de
  11. [1] , O.Lampl; L.Böszörmenyi; Adaptive quality-aware programming with declarative QoS constraints

Web links

Wikibooks: Working with .NET: C #  - learning and teaching materials