Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
C Sharp

C Sharp

Overview
C# (pronounced "C Sharp") is a multi-paradigm programming language
Multi-paradigm programming language
Programming languages can be grouped by the number an
Discussion
Ask a question about 'C Sharp'
Start a new discussion about 'C Sharp'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
C# (pronounced "C Sharp") is a multi-paradigm programming language
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article.Dataflow : forced recalculation of formulas when data values change...

 encompassing imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

, generic
Generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

, object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

 (class-based
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

), and component-oriented
Component-based software engineering
Component-based software engineering is a branch of software engineering, the priority of which is the separation of concerns in respect of the wide-ranging functionality available throughout a given software system...

 programming disciplines. It was developed by Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...

 within the .NET initiative and later approved as a standard by Ecma
Ecma International
Ecma International ' is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's international reach...

 (ECMA-334) and ISO
International Organization for Standardization
The International Organization for Standardization , widely known as ISO , is an international-standard-setting body composed of representatives from various national standards organizations. Founded on 23 February 1947, the organization promulgates worldwide proprietary industrial and commercial...

 (ISO/IEC 23270). C# is one of the programming languages designed for the Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

.

C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg
Anders Hejlsberg
Anders Hejlsberg is a prominent Danish software engineer who co-designed several popular and commercially successful programming languages and development tools...

, the designer of Borland
Borland
Borland Software Corporation is a software company headquartered in Austin, Texas.It is a Micro Focus company. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn....

's Turbo Pascal
Turbo Pascal
Turbo Pascal is a software development system that includes a compiler and an Integrated Development Environment for the Pascal programming language running under CP/M, CP/M-86, and MS-DOS, developed by Borland under Philippe Kahn's leadership...

. It has an object-oriented syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing sentences in natural languages...

 based on C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

. The most recent version of the language is 3.0
C Sharp 3.0
The programming language C# version 3.0 was released on 19 November, 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query pattern to the Common...

 which was released in conjunction with the .NET Framework
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

 3.5 in 2007. The next proposed version, 4.0
C Sharp 4.0
C# 4.0 is the latest version of the C# programming language, which has been finalized and is in beta testing as of May 2009. Microsoft has released the 4.0 runtime and development environment in a public beta of Visual Studio 2010. The major focus of C# 4.0 is interoperability with partially or...

, is in development.

Design goals


The Ecma standard lists these design goals for C#:
  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking
    Bounds checking
    In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array...

    , detection of attempts to use uninitialized variables, and automatic garbage collection
    Garbage collection (computer science)
    In computer science, garbage collection is a form of automatic memory management. It is a special case of resource management, in which the limited resource being managed is memory. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no...

    . Software robustness, durability, and programmer productivity are important.
  • The language is intended for use in developing software components suitable for deployment in distributed environments.
  • Source code portability is very important, as is programmer portability, especially for those programmers already familiar with C and C++.
  • Support for internationalization
    Internationalization
    In economics, internationalization has been viewed as a process of increasing involvement of enterprises in international markets, although there is no agreed definition of internationalization or international entrepreneurship...

     is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded system
    Embedded system
    An embedded system is a computer system designed to perform one or a few dedicated functions , often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal...

    s, ranging from the very large that use sophisticated operating system
    Operating system
    An operating system is an interface between hardware and user which is responsible for the management and coordination of activities and the sharing of the resources of the computer that acts as a host for computing applications run on the machine. As a host, one of the purposes of an operating...

    s, down to the very small having dedicated functions.
  • Although C# applications are intended to be economical with regard to memory and processing power
    Clock rate
    The clock rate is the fundamental rate in cycles per second for the frequency of the clock in any synchronous circuit. For example, a crystal oscillator frequency reference typically is synonymous with a fixed sinusoidal waveform, a clock rate is that frequency reference translated by electronic...

     requirements, the language was not intended to compete directly on performance and size with C or assembly language.

Language name


The name "C sharp" was inspired from musical notation
Musical notation
Music notation or musical notation is any system which represents aurally perceived music, through the use of written symbols.-Western history:...

 where a sharp
Sharp (music)
In music, sharp means higher in pitch. More specifically, in musical notation, sharp means "higher in pitch by a semitone ," and has an associated symbol , which is often confused with the number sign...

 indicates that the written note should be made a half-step higher in pitch. This is similar to the language name of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, where "++" indicates that a variable should be incremented by 1. The sharp symbol also resembles a ligature of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

.

Due to technical limitations of display (fonts, browsers, etc.) and the fact that the sharp symbol (
{{pound|C# (programming language)}}

{{infobox programming language
| name = C#
| year = 2001
| designer =
Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...


| latest_release_version = 3
| latest_release_date = 19 November 2007
| implementations = .NET Framework
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

, Mono
Mono (software)
Mono is a free and open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime...

, DotGNU
DotGNU
DotGNU is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework by Free Software Foundation. Other goals of the project are better support for non-Windows platforms and support for more processors....


| influenced_by = Object Pascal
Object Pascal
Object Pascal refers to a branch of object-oriented derivatives of Pascal, mostly known as the primary programming language of Delphi. Pascal compilers, including those for Object Pascal, generally run very fast while producing highly optimized code....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, Modula-3
Modula-3
In Computer science, Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2. While it has been influential in research circles it has not been adopted widely in industry...

, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed to enable programmers to efficiently develop extensible, reusable, reliable software. Eiffel is used in academia as a language for teaching computer-programming principles. Eiffel is used in the finance, aerospace,...


| typing = static, strong, safe, nominative
Nominative type system
In computer science a nominal or nominative type system is a major class of type system, in which compatibility and equivalence of data types is determined by explicit declarations and/or the name of the types. Nominative systems are used to determine if types are equivalent, as well as if a type...


| versions = 1.0, 1.5 , 2.0 (ECMA), 3.0
| influenced = F#, Nemerle
Nemerle
Nemerle is a high-level statically typed programming language for the .NET platform. It offers functional, object-oriented and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system....

, D, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Vala
Vala (programming language)
Vala is a programming language that tries to bring modern language features to C, without additional runtime requirements and with little overhead, by targeting the GObject object system. It was developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...

, Windows PowerShell
Windows PowerShell
Windows PowerShell is an extensible automation engine, consisting of a command-line shell and associated scripting language from Microsoft...


| paradigm = multi-paradigm
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article.Dataflow : forced recalculation of formulas when data values change...

: structured
Structured programming
Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement....

, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

, event-driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...


| dialects = Cω, Spec#
Spec sharp
Spec# is a programming language with specification language features that extends the capabilities of the C# programming language with Eiffel-like contracts, including object invariants, preconditions and postconditions. Like ESC/Java, it includes a static checking tool based on a theorem prover...

, Polyphonic C#
Polyphonic C sharp
Polyphonic C# is an extension of the C# programming language.It includes a new concurrency model in which objects can have both synchronous and asynchronous methods...


| license = CLR
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 Proprietary
}}

C# (pronounced "C Sharp") is a multi-paradigm programming language
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article.Dataflow : forced recalculation of formulas when data values change...

 encompassing imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

, generic
Generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

, object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

 (class-based
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

), and component-oriented
Component-based software engineering
Component-based software engineering is a branch of software engineering, the priority of which is the separation of concerns in respect of the wide-ranging functionality available throughout a given software system...

 programming disciplines. It was developed by Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...

 within the .NET initiative and later approved as a standard by Ecma
Ecma International
Ecma International ' is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's international reach...

 (ECMA-334) and ISO
International Organization for Standardization
The International Organization for Standardization , widely known as ISO , is an international-standard-setting body composed of representatives from various national standards organizations. Founded on 23 February 1947, the organization promulgates worldwide proprietary industrial and commercial...

 (ISO/IEC 23270). C# is one of the programming languages designed for the Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

.

C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg
Anders Hejlsberg
Anders Hejlsberg is a prominent Danish software engineer who co-designed several popular and commercially successful programming languages and development tools...

, the designer of Borland
Borland
Borland Software Corporation is a software company headquartered in Austin, Texas.It is a Micro Focus company. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn....

's Turbo Pascal
Turbo Pascal
Turbo Pascal is a software development system that includes a compiler and an Integrated Development Environment for the Pascal programming language running under CP/M, CP/M-86, and MS-DOS, developed by Borland under Philippe Kahn's leadership...

. It has an object-oriented syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing sentences in natural languages...

 based on C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

. The most recent version of the language is 3.0
C Sharp 3.0
The programming language C# version 3.0 was released on 19 November, 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query pattern to the Common...

 which was released in conjunction with the .NET Framework
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

 3.5 in 2007. The next proposed version, 4.0
C Sharp 4.0
C# 4.0 is the latest version of the C# programming language, which has been finalized and is in beta testing as of May 2009. Microsoft has released the 4.0 runtime and development environment in a public beta of Visual Studio 2010. The major focus of C# 4.0 is interoperability with partially or...

, is in development.

Design goals


The Ecma standard lists these design goals for C#:
  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking
    Bounds checking
    In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array...

    , detection of attempts to use uninitialized variables, and automatic garbage collection
    Garbage collection (computer science)
    In computer science, garbage collection is a form of automatic memory management. It is a special case of resource management, in which the limited resource being managed is memory. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no...

    . Software robustness, durability, and programmer productivity are important.
  • The language is intended for use in developing software components suitable for deployment in distributed environments.
  • Source code portability is very important, as is programmer portability, especially for those programmers already familiar with C and C++.
  • Support for internationalization
    Internationalization
    In economics, internationalization has been viewed as a process of increasing involvement of enterprises in international markets, although there is no agreed definition of internationalization or international entrepreneurship...

     is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded system
    Embedded system
    An embedded system is a computer system designed to perform one or a few dedicated functions , often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal...

    s, ranging from the very large that use sophisticated operating system
    Operating system
    An operating system is an interface between hardware and user which is responsible for the management and coordination of activities and the sharing of the resources of the computer that acts as a host for computing applications run on the machine. As a host, one of the purposes of an operating...

    s, down to the very small having dedicated functions.
  • Although C# applications are intended to be economical with regard to memory and processing power
    Clock rate
    The clock rate is the fundamental rate in cycles per second for the frequency of the clock in any synchronous circuit. For example, a crystal oscillator frequency reference typically is synonymous with a fixed sinusoidal waveform, a clock rate is that frequency reference translated by electronic...

     requirements, the language was not intended to compete directly on performance and size with C or assembly language.

Language name


The name "C sharp" was inspired from musical notation
Musical notation
Music notation or musical notation is any system which represents aurally perceived music, through the use of written symbols.-Western history:...

 where a sharp
Sharp (music)
In music, sharp means higher in pitch. More specifically, in musical notation, sharp means "higher in pitch by a semitone ," and has an associated symbol , which is often confused with the number sign...

 indicates that the written note should be made a half-step higher in pitch. This is similar to the language name of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, where "++" indicates that a variable should be incremented by 1. The sharp symbol also resembles a ligature of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

.

Due to technical limitations of display (fonts, browsers, etc.) and the fact that the sharp symbol (
{{pound|C# (programming language)}}

{{infobox programming language
| name = C#
| year = 2001
| designer =
Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...


| latest_release_version = 3
| latest_release_date = 19 November 2007
| implementations = .NET Framework
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

, Mono
Mono (software)
Mono is a free and open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime...

, DotGNU
DotGNU
DotGNU is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework by Free Software Foundation. Other goals of the project are better support for non-Windows platforms and support for more processors....


| influenced_by = Object Pascal
Object Pascal
Object Pascal refers to a branch of object-oriented derivatives of Pascal, mostly known as the primary programming language of Delphi. Pascal compilers, including those for Object Pascal, generally run very fast while producing highly optimized code....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, Modula-3
Modula-3
In Computer science, Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2. While it has been influential in research circles it has not been adopted widely in industry...

, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed to enable programmers to efficiently develop extensible, reusable, reliable software. Eiffel is used in academia as a language for teaching computer-programming principles. Eiffel is used in the finance, aerospace,...


| typing = static, strong, safe, nominative
Nominative type system
In computer science a nominal or nominative type system is a major class of type system, in which compatibility and equivalence of data types is determined by explicit declarations and/or the name of the types. Nominative systems are used to determine if types are equivalent, as well as if a type...


| versions = 1.0, 1.5 , 2.0 (ECMA), 3.0
| influenced = F#, Nemerle
Nemerle
Nemerle is a high-level statically typed programming language for the .NET platform. It offers functional, object-oriented and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system....

, D, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Vala
Vala (programming language)
Vala is a programming language that tries to bring modern language features to C, without additional runtime requirements and with little overhead, by targeting the GObject object system. It was developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...

, Windows PowerShell
Windows PowerShell
Windows PowerShell is an extensible automation engine, consisting of a command-line shell and associated scripting language from Microsoft...


| paradigm = multi-paradigm
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article.Dataflow : forced recalculation of formulas when data values change...

: structured
Structured programming
Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement....

, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

, event-driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...


| dialects = Cω, Spec#
Spec sharp
Spec# is a programming language with specification language features that extends the capabilities of the C# programming language with Eiffel-like contracts, including object invariants, preconditions and postconditions. Like ESC/Java, it includes a static checking tool based on a theorem prover...

, Polyphonic C#
Polyphonic C sharp
Polyphonic C# is an extension of the C# programming language.It includes a new concurrency model in which objects can have both synchronous and asynchronous methods...


| license = CLR
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 Proprietary
}}

C# (pronounced "C Sharp") is a multi-paradigm programming language
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article.Dataflow : forced recalculation of formulas when data values change...

 encompassing imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

, generic
Generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

, object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data...

 (class-based
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

), and component-oriented
Component-based software engineering
Component-based software engineering is a branch of software engineering, the priority of which is the separation of concerns in respect of the wide-ranging functionality available throughout a given software system...

 programming disciplines. It was developed by Microsoft
Microsoft
Microsoft Corporation is a multinational computer technology corporation that develops, manufactures, licenses, and supports a wide range of software products for computing devices...

 within the .NET initiative and later approved as a standard by Ecma
Ecma International
Ecma International ' is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's international reach...

 (ECMA-334) and ISO
International Organization for Standardization
The International Organization for Standardization , widely known as ISO , is an international-standard-setting body composed of representatives from various national standards organizations. Founded on 23 February 1947, the organization promulgates worldwide proprietary industrial and commercial...

 (ISO/IEC 23270). C# is one of the programming languages designed for the Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

.

C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg
Anders Hejlsberg
Anders Hejlsberg is a prominent Danish software engineer who co-designed several popular and commercially successful programming languages and development tools...

, the designer of Borland
Borland
Borland Software Corporation is a software company headquartered in Austin, Texas.It is a Micro Focus company. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn....

's Turbo Pascal
Turbo Pascal
Turbo Pascal is a software development system that includes a compiler and an Integrated Development Environment for the Pascal programming language running under CP/M, CP/M-86, and MS-DOS, developed by Borland under Philippe Kahn's leadership...

. It has an object-oriented syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing sentences in natural languages...

 based on C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

. The most recent version of the language is 3.0
C Sharp 3.0
The programming language C# version 3.0 was released on 19 November, 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query pattern to the Common...

 which was released in conjunction with the .NET Framework
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

 3.5 in 2007. The next proposed version, 4.0
C Sharp 4.0
C# 4.0 is the latest version of the C# programming language, which has been finalized and is in beta testing as of May 2009. Microsoft has released the 4.0 runtime and development environment in a public beta of Visual Studio 2010. The major focus of C# 4.0 is interoperability with partially or...

, is in development.

Design goals


The Ecma standard lists these design goals for C#:
  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking
    Bounds checking
    In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array...

    , detection of attempts to use uninitialized variables, and automatic garbage collection
    Garbage collection (computer science)
    In computer science, garbage collection is a form of automatic memory management. It is a special case of resource management, in which the limited resource being managed is memory. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no...

    . Software robustness, durability, and programmer productivity are important.
  • The language is intended for use in developing software components suitable for deployment in distributed environments.
  • Source code portability is very important, as is programmer portability, especially for those programmers already familiar with C and C++.
  • Support for internationalization
    Internationalization
    In economics, internationalization has been viewed as a process of increasing involvement of enterprises in international markets, although there is no agreed definition of internationalization or international entrepreneurship...

     is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded system
    Embedded system
    An embedded system is a computer system designed to perform one or a few dedicated functions , often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal...

    s, ranging from the very large that use sophisticated operating system
    Operating system
    An operating system is an interface between hardware and user which is responsible for the management and coordination of activities and the sharing of the resources of the computer that acts as a host for computing applications run on the machine. As a host, one of the purposes of an operating...

    s, down to the very small having dedicated functions.
  • Although C# applications are intended to be economical with regard to memory and processing power
    Clock rate
    The clock rate is the fundamental rate in cycles per second for the frequency of the clock in any synchronous circuit. For example, a crystal oscillator frequency reference typically is synonymous with a fixed sinusoidal waveform, a clock rate is that frequency reference translated by electronic...

     requirements, the language was not intended to compete directly on performance and size with C or assembly language.

Language name


The name "C sharp" was inspired from musical notation
Musical notation
Music notation or musical notation is any system which represents aurally perceived music, through the use of written symbols.-Western history:...

 where a sharp
Sharp (music)
In music, sharp means higher in pitch. More specifically, in musical notation, sharp means "higher in pitch by a semitone ," and has an associated symbol , which is often confused with the number sign...

 indicates that the written note should be made a half-step higher in pitch. This is similar to the language name of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, where "++" indicates that a variable should be incremented by 1. The sharp symbol also resembles a ligature of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

.

Due to technical limitations of display (fonts, browsers, etc.) and the fact that the sharp symbol ({{music
Sharp (music)
In music, sharp means higher in pitch. More specifically, in musical notation, sharp means "higher in pitch by a semitone ," and has an associated symbol , which is often confused with the number sign...

, U+266F, MUSIC SHARP SIGN) is not present on the standard keyboard, the number sign
Number sign
Number sign is a name for the symbol #, which is used for a variety of purposes including the designation of a number . "Number sign" is the preferred Unicode name for the code point...

 (#, U+0023, NUMBER SIGN) was chosen to represent the sharp symbol in the written name of the programming language. This convention is reflected in the ECMA-334 C# Language Specification. However, when it is practical to do so (for example, in advertising or in box art), Microsoft uses the intended musical symbol.

The "sharp" suffix has been used by a number of other .NET languages that are variants of existing languages, including J#
J Sharp
The J# programming language is a transitional language for programmers of Sun's Java and Microsoft's Visual J++ languages, so they may use their existing knowledge and applications on Microsoft's .NET platform...

 (a .NET language also designed by Microsoft which is derived from Java 1.1), A#
A Sharp (.NET)
A# is a port of the Ada programming language to the Microsoft .NET platform. A# is freely distributed by the Department of Computer Science at the United States Air Force Academy as a service to the Ada community under the terms of the GNU General Public License.AdaCore has taken over this...

 (from Ada), and the functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 F#. The original implementation of Eiffel for .NET
EiffelStudio
EiffelStudio is a development environment for the Eiffel programming language developed and distributed by Eiffel Software.EiffelStudio includes a combination of tools integrated under a single user interface: compiler, interpreter, debugger, browser, metrics tool, profiler, diagram tool...

 was called Eiffel#, a name since retired since the full Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed to enable programmers to efficiently develop extensible, reusable, reliable software. Eiffel is used in academia as a language for teaching computer-programming principles. Eiffel is used in the finance, aerospace,...

 language is now supported. The suffix has also been used for libraries, such as Gtk#
Gtk Sharp
Gtk# is a set of .NET bindings for the GTK+ GUI toolkit and assorted GNOME libraries. The library facilitates building graphical GNOME applications using Mono or any other compliant CLR...

 (a .NET wrapper for GTK+
GTK+
GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is one of the most popular toolkits for the X Window System, along with Qt....

 and other GNOME
GNOME
GNOME is a desktop environment—a graphical user interface which runs on top of a computer operating system —composed entirely of free and open source software...

 libraries), Cocoa#
Cocoa Sharp
Cocoa# is a bridge framework on Mac OS X to allow applications developed with the Mono runtime to access the Cocoa API. It provides direct access to the Cocoa API using a dot notation familiar to languages working on the Mono runtime such as C#....

 (a wrapper for Cocoa
Cocoa (API)
Cocoa is one of Apple Inc.'s native object-oriented application program environments for the Mac OS X operating system. It is one of five major APIs available for Mac OS X; the others are Carbon , POSIX , X11 and Java....

) and Qt# (a .NET language binding for the Qt toolkit
Qt (toolkit)
Qt is a cross-platform application development framework, widely used for the development of GUI programs , and also used for developing non-GUI programs such as console tools and servers. Qt is most notably used in KDE, Google Earth, Skype, Qt Extended, Adobe Photoshop Album, VirtualBox and OPIE...

).

History


During the development of .NET Framework, the class libraries
Base Class Library
The Base Class Library is a standard library available to all languages using the .NET Framework. .NET includes the BCL in order to encapsulate a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation, which makes...

 were originally written using a managed code
Managed code
Managed code is computer program code that executes under the management of a virtual machine, unlike unmanaged code, which is executed directly by the computer's CPU. The benefits of managed code include programmer convenience and enhanced security guarantees.Programs in any programming language...

 compiler system called Simple Managed C (SMC). In January 1999, Anders Hejlsberg
Anders Hejlsberg
Anders Hejlsberg is a prominent Danish software engineer who co-designed several popular and commercially successful programming languages and development tools...

 formed a team to build a new language at the time called Cool, which stood for "C-like Object Oriented Language". Microsoft had considered keeping the name "Cool" as the final name of the language, but chose not to do so for trademark reasons. By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference
Professional Developers Conference
Microsoft's Professional Developers Conference is a conference for software developers, normally Windows developers.It covers new and upcoming technology from Microsoft, and so only occurs in the years when there is something new to talk about...

, the language had been renamed C#, and the class libraries and ASP.NET
ASP.NET
ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages ...

 runtime had been ported to C#.

C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg, who was previously involved with the design of Turbo Pascal
Turbo Pascal
Turbo Pascal is a software development system that includes a compiler and an Integrated Development Environment for the Pascal programming language running under CP/M, CP/M-86, and MS-DOS, developed by Borland under Philippe Kahn's leadership...

, CodeGear Delphi  (formerly Borland Delphi), and Visual J++
Visual J++
Visual J++ was Microsoft's specific implementation of Java. Optimized for the Windows Platform, J++ programs could only run on the MSJVM...

. In interviews and technical papers he has stated that flaws in most major programming languages (e.g. C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Delphi, and Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

) drove the fundamentals of the Common Language Runtime
Common Language Runtime
The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

 (CLR), which, in turn, drove the design of the C# programming language itself.

Versions


In the course of its development, the C# language has gone through several versions:
Version Language Specification Microsoft Compiler
C# 1.0 December 2001 January 2002
C# 2.0
C Sharp 2.0
The programming language C# introduces several new features in version 2.0 . These include:- Partial class :...

December 2002 November 2005
C# 3.0
C Sharp 3.0
The programming language C# version 3.0 was released on 19 November, 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query pattern to the Common...

June 2005 November 2006
C# 4.0
C Sharp 4.0
C# 4.0 is the latest version of the C# programming language, which has been finalized and is in beta testing as of May 2009. Microsoft has released the 4.0 runtime and development environment in a public beta of Visual Studio 2010. The major focus of C# 4.0 is interoperability with partially or...

June 2006 in development

Features


{{seealso|C Sharp syntax}}
Note: The following description is based on the language standard and other documents listed in the external links section.


By design, C# is the programming language that most directly reflects the underlying Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

 (CLI). Most of its intrinsic types correspond to value-types implemented by the CLI framework. However, the language specification does not state the code generation requirements of the compiler: that is, it does not state that a C# compiler must target a Common Language Runtime, or generate Common Intermediate Language
Common Intermediate Language
Common Intermediate Language is the lowest-level human-readable programming language in the Common Language Infrastructure and in the .NET Framework. Languages which target the .NET Framework compile to CIL, which is assembled into bytecode...

 (CIL), or generate any other specific format. Theoretically, a C# compiler could generate machine code like traditional compilers of C++ or FORTRAN. In practice, all existing compiler implementations target CIL.

Some notable distinguishing features of C# are:
  • There are no global variables or functions. All methods and members must be declared within classes. Static members of public classes can substitute for global variables and functions.
  • Local variables cannot shadow variables of the enclosing block, unlike C and C++. Variable shadowing
    Variable shadowing
    In computer programming, variable shadowing occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. This outer variable is said to be shadowed...

     is often considered confusing by C++ texts.

  • C# supports a strict Boolean datatype
    Boolean datatype
    In computer science, the Boolean or logical data type is a primitive data type having one of two values: true or false, intended to represent the truth values of logic and Boolean algebra....

    , bool. Statements that take conditions, such as while and if, require an expression of a boolean type. While C++ also has a boolean type, it can be freely converted to and from integers, and expressions such as if(a) require only that a is convertible to bool, allowing a to be an int, or a pointer. C# disallows this "integer meaning true or false" approach on the grounds that forcing programmers to use expressions that return exactly bool can prevent certain types of programming mistakes such as if (a = b) (use of = instead of ).
  • In C#, memory address pointers can only be used within blocks specifically marked as unsafe, and programs with unsafe code need appropriate permissions to run. Most object access is done through safe object references, which always either point to a "live" object or have the well-defined null value; it is impossible to obtain a reference to a "dead" object (one which has been garbage collected), or to a random block of memory. An unsafe pointer can point to an instance of a value-type, array, string, or a block of memory allocated on a stack. Code that is not marked as unsafe can still store and manipulate pointers through the System.IntPtr type, but it cannot dereference them.
  • Managed memory cannot be explicitly freed; instead, it is automatically garbage collected. Garbage collection addresses memory leak
    Memory leak
    A memory leak or leakage in computer science is a particular type of memory consumption by a computer program where the program is unable to release memory it has acquired...

    s by freeing the programmer of responsibility for releasing memory which is no longer needed. C# also provides direct support for deterministic finalization with the using statement (supporting the Resource Acquisition Is Initialization
    Resource Acquisition Is Initialization
    Resource Acquisition Is Initialization, often referred to by the acronym RAII , is a popular design pattern in several object oriented programming languages like C++, D and Ada. The technique was invented by Bjarne Stroustrup, to deal with resource deallocation in C++...

     idiom).
  • Multiple inheritance
    Multiple inheritance
    Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass...

     is not supported, although a class can implement any number of interfaces. This was a design decision by the language's lead architect to avoid complication, avoid dependency hell
    Dependency hell
    Dependency hell is a colloquial term for the frustration of some software users who have installed software packages which have dependencies on specific versions of other software packages.- Overview :...

     and simplify architectural requirements throughout CLI.

  • C# is more typesafe than C++. The only implicit conversions by default are those which are considered safe, such as widening of integers and conversion from a derived type to a base type. This is enforced at compile-time, during JIT
    Just-in-time compilation
    In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program. JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation...

    , and, in some cases, at runtime. There are no implicit conversions between booleans and integers, nor between enumeration members and integers (except for literal 0, which can be implicitly converted to any enumerated type). Any user-defined conversion must be explicitly marked as explicit or implicit, unlike C++ copy constructor
    Copy constructor
    A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object. The first argument of such a constructor is a reference to an object of the same type as is being constructed , which might be followed by parameters of any type...

    s and conversion operators, which are both implicit by default.
  • Enumeration
    Enumerated type
    In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language...

     members are placed in their own scope
    Scope (programming)
    In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes. The type of scope determines what kind of entities it can contain and how it affects them -- or semantics...

    .
  • C# provides properties
    Property (programming)
    In some object-oriented programming languages, a property is a special sort of class member, intermediate between a field and a method. Properties are read and written like fields, but property reads and writes are translated to get and set method calls...

     as syntactic sugar
    Syntactic sugar
    In computer science, syntactic sugar in a language is syntax designed to make things easier to read or to express, while alternative ways of expressing them exist....

     for a common pattern in which a pair of methods, accessor (getter) and mutator (setter)
    Mutator method
    In computer science, a mutator method is a method used to control changes to a variable.The mutator method, sometimes called a "setter", is most often used in object-oriented programming, in keeping with the principle of encapsulation...

     encapsulate operations on a single attribute
    Attribute (computing)
    In computing, an attribute is a specification that defines a property of an object, element, or file. An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension....

     of a class.
  • Full type reflection
    Reflection (computer science)
    In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior. The programming paradigm driven by reflection is called reflective programming...

     and discovery is available.
  • C# currently (as of 3 June 2008) has 77 reserved word
    Reserved word
    Reserved words are one type of grammatical construct in programming languages. These words have special meaning within the language and are predefined in the language’s formal specifications...

    s.

Common Type system (CTS)
C# has a unified type system. This unified type system is called Common Type System
Common Type System
In Microsoft's .NET Framework, the Common Type System is a standard that specifies how Type definitions and specific values of Types are represented in...

 (CTS)
.

A unified type system implies that all types, including primitives such as integers, are subclasses of the System.Object class. For example, every type inherits a ToString method. For performance reasons, primitive types (and value types in general) are internally allocated on the stack
Stack-based memory allocation
Stacks in computing architectures are regions of memory where data is added or removed in a last-in-first-out manner.In most modern computer systems, each thread has a reserved region of memory referred to as its stack. When a function executes, it may add some of its state data to the top of the...

.

Categories of datatypes


CTS separates datatypes into two categories:
  1. Value types
  2. Reference types


Value types are plain aggregations of data. Instances of value types do not have referential identity nor a referential comparison semantics - equality and inequality comparisons for value types compare the actual data values within the instances, unless the corresponding operators are overloaded. Value types are derived from System.ValueType, always have a default value, and can always be created and copied. Some other limitations on value types are that they cannot derive from each other (but can implement interfaces) and cannot have a default (parameterless) constructor. Examples of value types are some primitive types, such as int (a signed 32-bit integer), float (a 32-bit IEEE floating-point number), char (a 16-bit Unicode code unit), and System.DateTime (identifies a specific point in time with millisecond precision).

In contrast, reference types have the notion of referential identity - each instance of reference type is inherently distinct from every other instance, even if the data within both instances is the same. This is reflected in default equality and inequality comparisons for reference types, which test for referential rather than structural equality, unless the corresponding operators are overloaded (such as the case for System.String). In general, it is not always possible to create an instance of a reference type, nor to copy an existing instance, or perform a value comparison on two existing instances, though specific reference types can provide such services by exposing a public constructor or implementing a corresponding interface (such as ICloneable or IComparable). Examples of reference types are object (the ultimate base class for all other C# classes), System.String (a string of Unicode characters), and System.Array (a base class for all C# arrays).

Both type categories are extensible with user-defined types.

Boxing and unboxing


Boxing is the operation of converting a value of a value type into a value of a corresponding reference type. Boxing in C# is implicit.

Unboxing is the operation of converting a value of a reference type (previously boxed) into a value of a value type. Unboxing in C# requires an explicit type cast.

Example:

int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.

Preprocessor
C# features "preprocessor directives" (though it does not have an actual preprocessor) based on the C preprocessor
C preprocessor
The C preprocessor is the preprocessor for the C programming language. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The preprocessor handles directives for source file inclusion , macro definitions , and conditional inclusion...

 that allow programmers to define symbols but not macros. Conditionals such as #if, #endif, and #else are also provided. Directives such as #region give hints to editors for code folding
Code folding
Code folding is a feature of some text editors, source code editors and IDEs that allows the user to selectively hide and display sections of a currently-edited file as a part of routine edit operations...

.
Code comments
C# utilizes a double forward slash (//) to indicate the rest of the line is a comment.


public class Foo
{
// a comment
public static void Bar(int firstParam) {} //Also a comment
}


Multi-line comments can be indicated by a starting forward slash/asterisk (/*) and ending asterisk/forward slash (*/).


public class Foo
{
/* A Multi-Line
comment */
public static void Bar(int firstParam) {}
}

XML documentation system
C#'s documentation system is similar to Java's Javadoc
Javadoc
Javadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs , such as Netbeans and Eclipse will automatically...

, but based on XML
Extensible Markup Language
XML is a set of rules for encoding documents electronically. It is defined in the produced by the W3C and several other related specifications; all are fee-free open standards....

. Two methods of documentation are currently supported by the C# compiler
Compiler
A compiler is a computer program that transforms source code written in a computer language into another computer language...

.

Single-line documentation comments, such as those commonly found in Visual Studio
Microsoft Visual Studio
Microsoft Visual Studio is an Integrated Development Environment from Microsoft. It can be used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

 generated code, are indicated on a line beginning with ///.


public class Foo
{
/// A summary of the method.
/// A description of the parameter.
/// Remarks about the method.
public static void Bar(int firstParam) {}
}


Multi-line documentation comments, while defined in the version 1.0 language specification, were not supported until the .NET
.NET Framework
The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for...

 1.1 release. These comments are designated by a starting forward slash/asterisk/asterisk (/**) and ending asterisk/forward slash (*/).


public class Foo
{
/** A summary of the method.
* A description of the parameter.
* Remarks about the method. */
public static void Bar(int firstParam) {}
}


Note there are some stringent criteria regarding white space and XML documentation when using the forward slash/asterisk/asterisk (/**) technique.

This code block:

/**
*
* A summary of the method.
*/


produces a different XML comment than this code block:

/**
*
A summary of the method.
*/


Syntax for documentation comments and their XML
XML
XML is a set of rules for encoding documents electronically. It is defined in the produced by the W3C and several other related specifications; all are fee-free open standards....

 markup is defined in a non-normative annex of the ECMA
Ecma International
Ecma International ' is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's international reach...

 C# standard. The same standard also defines rules for processing of such comments, and their transformation to a plain XML
XML
XML is a set of rules for encoding documents electronically. It is defined in the produced by the W3C and several other related specifications; all are fee-free open standards....

 document with precise rules for mapping of CLI
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

 identifiers to their related documentation elements. This allows any C# IDE
Integrated development environment
An integrated development environment also known as integrated design environment or integrated debugging environment is a software application that provides comprehensive facilities to computer programmers for software development...

 or other development tool to find documentation for any symbol in the code in a certain well-defined way.
Libraries
The C# specification details a minimum set of types and class libraries that the compiler expects to have available. In practice, C# is most often used with some implementation of the Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

 (CLI), which is standardized as ECMA-335 Common Language Infrastructure (CLI).
"Hello, world" example
The following is a very simple C# program, a version of the classic "Hello, world" example:


class ExampleClass
{
static void Main
{
System.Console.WriteLine("Hello, world!");
}
}


The effect is to write the following text to the output console:

Hello, world!

Each line has a purpose:


class ExampleClass


Above is a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that...

 definition. Everything between the following pair of braces describes ExampleClass.


static void Main


This declares the class member method where the program begins execution. The .NET runtime calls the Main method. (Note: Main may also be called from elsewhere, e.g. from the code Main in another method of ExampleClass.) The static keyword makes the method accessible without an instance of ExampleClass. Each console application's Main entry point must be declared static. Otherwise, the program would require an instance, but any instance would require a program. To avoid that irresolvable circular dependency
Circular dependency
In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly.-Overview:...

, C# compilers processing console applications (like above) report an error if there is no static Main method. The void keyword declares that Main has no return value (see also side effect
Side effect (computer science)
In computer science, a function or expression is said to have a side effect if, in addition to producing a value, it also modifies some state or has an observable interaction with calling functions or the outside world...

).


System.Console.WriteLine("Hello, world!");


This line writes the output. Console is a static class in the System namespace. It provides an interface to the standard input, output, and error streams for console applications. The program calls the Console method WriteLine, which displays on the console a line with the argument, the string "Hello, world!".
Standardization
In August, 2000, Microsoft Corporation, Hewlett-Packard and Intel Corporation co-sponsored the submission of specifications for C# as well as the Common Language Infrastructure (CLI) to the standards organization ECMA International.
In December 2001, ECMA released ECMA-334 C# Language Specification. C# became an ISO standard in 2003 (ISO/IEC 23270:2006 - Information technology -- Programming languages -- C#). ECMA had previously adopted equivalent specifications as the 2nd edition of C#, in December 2002.

In June 2005, ECMA approved edition 3 of the C# specification, and updated ECMA-334. Additions included partial classes, anonymous methods, nullable types, and generics
Generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

 (similar to C++ templates
Template (programming)
Templates are a feature of the C++ programming language that allow functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one....

).

In July 2005, ECMA submitted the standards and related TRs to ISO/IEC JTC 1 via the latter's Fast-Track process. This process usually takes 6–9 months.

Criticism


Although the C# language definition and the CLI
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

 are standardized under ISO and Ecma
ECMA
Ecma or ECMA may refer to:* Ecma International, an international standards organization for Information Communication Technology and Consumer Electronics* Engineering College Magazines Associated, a group of student-run engineering-based publications...

 standards which provide reasonable and non-discriminatory licensing
Reasonable and Non Discriminatory Licensing
Reasonable and Non Discriminatory Licensing is a term for a type of licensing typically used during standardization processes. The normal case is that when joining the standardization body, companies agree that if they receive any patents on technologies which become essential to the standard...

 protection from patent claims, Microsoft uses C# and the CLI in its Base Class Library
Base Class Library
The Base Class Library is a standard library available to all languages using the .NET Framework. .NET includes the BCL in order to encapsulate a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation, which makes...

 (BCL) which is the foundation of its proprietary .NET framework, and which provides a variety of non-standardized classes (extended I/O
Input/output
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world – possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...

, GUI
Windows Forms
Windows Forms is the name given to the graphical application programming interface included as a part of Microsoft's .NET Framework, providing access to the native Microsoft Windows interface elements by wrapping the existing Windows API in managed code...

, web service
Web service
A Web service is defined by the W3C as "a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format...

s, etc). Some cases where Microsoft patents apply to standards used in the .NET framework are documented by Microsoft and the applicable patents are available on either RAND terms or through Microsoft's Open Specification Promise
Microsoft Open Specification Promise
The Microsoft Open Specification Promise , is an irrevocable promise by Microsoft, published in September 2006, to not assert legal rights over certain Microsoft patents on implementations of an included list of technologies....

 which releases patent rights to the public, but there is some concern and debate as to whether there are additional aspects patented by Microsoft which are not covered, which may deter independent implementations of the full framework. Microsoft has also agreed not to sue open source developers for violating patents in non-profit projects for the part of the framework which is covered by the OSP. Microsoft has agreed not to enforce patents relating to Novell
Novell
Novell, Inc. is a global software corporation based in the United States specializing in enterprise operating systems such as SUSE Linux Enterprise and Novell NetWare; identity, security and systems management solutions; and collaboration solutions. Together with WordPerfect, Novell was...

 products against Novell's paying customers with the exception of a list of products that do not explicitly mention C#, .NET or Novell's implementation of .NET (The Mono Project
Mono (software)
Mono is a free and open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime...

),. However Novell maintains that Mono does not infringe any Microsoft patents. Microsoft has also made a specific agreement not to enforce patent rights related to the Moonlight browser plugin, which depends on Mono, provided it is obtained through Novell
Novell
Novell, Inc. is a global software corporation based in the United States specializing in enterprise operating systems such as SUSE Linux Enterprise and Novell NetWare; identity, security and systems management solutions; and collaboration solutions. Together with WordPerfect, Novell was...

.

In a note posted on the Free Software Foundation
Free Software Foundation
The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to distribute and modify computer software...

's news website in June 2009, Richard Stallman
Richard Stallman
Richard Matthew Stallman , often abbreviated "rms","'Richard Stallman' is just my mundane name; you can call me 'rms'"|last= Stallman|first= Richard|date= N.D.|work=Richard Stallman's homepage...

 warned that he believes "Microsoft is probably planning to force all free C# implementations underground some day using software patents" and recommended that developers avoid taking what he described as the "gratuitous risk" associated with "depend[ing] on the free C# implementations".. The Free Software Foundation
Free Software Foundation
The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to distribute and modify computer software...

 later reiterated its warnings, claiming that the extension of Microsoft Community Promise to the C# and the CLI ECMA specifications would not prevent Microsoft from harming Open-Source implementations of C#, because many specific Windows libraries included with .NET or Mono
Mono (software)
Mono is a free and open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime...

 were not covered by this promise.
Implementations
The reference C# compiler is Microsoft Visual C#
Microsoft Visual C Sharp
Microsoft Visual C# is Microsoft's implementation of the C# programming language specification, included in the Microsoft Visual Studio suite of products. It is based on the ECMA/ISO specification of the C# language, which Microsoft also created. While multiple implementations of the specification...

.

Other C# compilers exist, often including an implementation of the Common Language Infrastructure
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

 and the .NET class libraries up to .NET 2.0:
  • Microsoft's Rotor project (currently called Shared Source Common Language Infrastructure
    Shared Source Common Language Infrastructure
    The Shared Source Common Language Infrastructure , previously codenamed Rotor, is Microsoft's shared source implementation of the CLI, the core of .NET. Although the SSCLI is not suitable for commercial use due to its license, it does make it possible for programmers to examine the implementation...

    ) (licensed for educational and research use only) provides a shared source
    Shared source
    Shared source is Microsoft's framework for sharing computer program source code with third parties. Microsoft's Shared Source Initiative, launched in May 2007, includes a spectrum of technologies and licenses...

     implementation of the CLR runtime and a C# compiler, and a subset of the required Common Language Infrastructure
    Common Language Infrastructure
    The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

     framework libraries in the ECMA specification (up to C# 2.0, and supported on Windows XP only).
  • The Mono
    Mono (software)
    Mono is a free and open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime...

     project provides an open source
    Open source
    Open source is an approach to the design, development, and distribution of software, offering practical accessibility to a software's source code. Some consider open source as one of various possible design approaches, while others consider it a critical strategic element of their operations...

     C# compiler, a complete open source implementation of the Common Language Infrastructure including the required framework libraries as they appear in the ECMA specification, and a nearly complete implementation of the Microsoft proprietary .NET class libraries up to .NET 2.0, but not specific .NET 3.0 and .NET 3.5 libraries, as of Mono 2.0.
  • The DotGNU
    DotGNU
    DotGNU is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework by Free Software Foundation. Other goals of the project are better support for non-Windows platforms and support for more processors....

     project also provides an open source C# compiler, a nearly complete implementation of the Common Language Infrastructure including the required framework libraries as they appear in the ECMA specification, and subset of some of the remaining Microsoft proprietary .NET class libraries up to .NET 2.0 (those not documented or included in the ECMA specification but included in Microsoft's standard .NET Framework distribution).
  • The DotNetAnywhere Micro Framework-like Common Language Runtime
    Common Language Runtime
    The Common Language Runtime is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code...

     is targeted at embedded systems, and supports almost all C# 2.0 specifications.

See also
  • C# Syntax
    C Sharp syntax
    This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.-Identifier:An identifier is the name of an element in the code...

  • Sing#
    Sing sharp
    Sing# is a concurrent programming language that is a superset of the Spec# programming language; in turn, Spec# is an extension of the C# programming language. Microsoft Research developed Spec#, and later extended it into Sing# in order to develop the Singularity operating system...

  • Mono and Microsoft’s patents
  • .NET Framework Standardization and licensing
  • Oxygene
  • Microsoft Visual Studio
    Microsoft Visual Studio
    Microsoft Visual Studio is an Integrated Development Environment from Microsoft. It can be used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

    , IDE for C#
  • SharpDevelop
    SharpDevelop
    SharpDevelop is a free and open source IDE for the C#, Visual Basic .NET , Boo, and F# and IronPython programming languages.It is typically used as an alternative to Microsoft's Visual Studio .NET...

    , an open-source C# IDE for Windows
    Microsoft Windows
    Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces...

  • MonoDevelop
    MonoDevelop
    MonoDevelop is an open source integrated development environment for the Linux platform, Mac OS X, and Microsoft Windows, primarily targeted for the development of software that uses both the Mono and Microsoft .NET framework...

    , an open-source C# IDE for Linux
    Linux
    Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed,...

     Windows
    Microsoft Windows
    Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces...

     and Mac OS X
    Mac OS X
    Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems...

  • Morfik
    Morfik
    Morfik Technology Pty Ltd., an Australian company, is the developer of WebOS AppsBuilder, an Integrated development environment aimed at developing Ajax applications in a high-level language such as Java, C#, BASIC or Object Pascal. Morfik includes visual design tools for forms, database...

     C#, a C# to JavaScript compiler complete with IDE and framework for Web application development.
  • Baltie
    Baltie
    Baltie is a proprietary educational computer programming language used as a learning aid for beginning programmers. Most commonly used to teach younger students with little or no experience in programming...

    , an educational IDE for children and students with little or no programming experience
  • Borland
    Borland
    Borland Software Corporation is a software company headquartered in Austin, Texas.It is a Micro Focus company. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn....

     Turbo C Sharp
    Turbo C Sharp
    Turbo C# was an Integrated Development Environment from Borland that came in two versions, Explorer and Professional. It uses the C# programming language to develop applications for WinForms and ASP.NET....

  • Learning C Sharp
    Learning C Sharp
    Learning C#, also known as the fish book, is a tutorial book for the C# programming language, and is published by O'Reilly. Authored by Jesse Liberty and Brian MacDonald in its second edition, and published in 2005, covering C# 2005 ....

    (book)

External links
{{Wikibooks|C Sharp Programming}}

{{DotNET}}
{{Ecma International Standards}}
{{ISO standards}}