C Sharp
Encyclopedia
C# is a multi-paradigm programming language
encompassing strong typing, imperative
, declarative
, functional
, generic
, object-oriented
(class-based
), and component-oriented
programming disciplines. It was developed by Microsoft
within its .NET
initiative and later approved as a standard by Ecma
(ECMA-334) and ISO
(ISO/IEC 23270). C# is one of the programming languages designed for the Common Language Infrastructure
.
C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg
. The most recent version is C# 4.0
, which was released on April 12, 2010.
where a sharp
indicates that the written note should be made a semitone
higher in pitch
. This is similar to the language name of C++
, where "++" indicates that a variable should be incremented by 1.
Due to technical limitations of display (standard fonts, browsers, etc.) and the fact that the sharp symbol is not present on the standard keyboard, the 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#
(a .NET language also designed by Microsoft that is derived from Java 1.1), A#
(from Ada
), and the functional programming
language F#. The original implementation of Eiffel for .NET
was called Eiffel#, a name since retired since the full Eiffel
language is now supported. The suffix has also been used for libraries, such as Gtk#
(a .NET wrapper for GTK+
and other GNOME
libraries), Cocoa#
(a wrapper for Cocoa
) and Qt# (a .NET language binding for the Qt toolkit
).
were originally written using a managed code
compiler system called Simple Managed C (SMC). In January 1999, Anders Hejlsberg
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
, the language had been renamed C#, and the class libraries and ASP.NET
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
, Embarcadero Delphi (formerly CodeGear Delphi and Borland Delphi), and Visual J++
. In interviews and technical papers he has stated that flaws in most major programming languages (e.g. C++
, Java
, Delphi, and Smalltalk
) drove the fundamentals of the Common Language Runtime
(CLR), which, in turn, drove the design of the C# language itself.
James Gosling
, who created the Java
programming language in 1994, and Bill Joy
, a co-founder of Sun Microsystems, the originator of Java, called C# an "imitation" of Java; Gosling further claimed that "[C# is] sort of Java with reliability, productivity and security deleted." Klaus Kreft and Angelika Langer (authors of a C++ streams book) stated in a blog post that "Java and C# are almost identical programming languages. Boring repetition that lacks innovation," "Hardly anybody will claim that Java or C# are revolutionary programming languages that changed the way we write programs," and "C# borrowed a lot from Java - and vice versa. Now that C# supports boxing and unboxing, we'll have a very similar feature in Java."
Anders Hejlsberg has argued that C# is "not a Java clone" and is "much closer to C++" in its design.
Since the release of C# 2.0 in November of 2005, the C# and Java languages have evolved on increasingly divergent trajectories, becoming somewhat less similar. One of the first major departures came with the addition of generics to both languages, with vastly different implementations. C# makes use of reification
to provide "first-class" generic objects that can be used like any other class, with code generation performed at class-load time. By contrast, Java's generics are essentially a language syntax feature, and they do not affect the generated byte code, because the compiler performs type erasure
on the generic type information after it has verified its correctness.
Furthermore, C# has added several major features to accommodate functional-style programming, culminating in their LINQ
extensions released with C# 3.0 and its supporting framework of lambda expressions, extension method
s, and anonymous classes. These features enable C# programmers to use functional programming techniques, such as closures
, when it is advantageous to their application. The LINQ extensions and the functional imports help developers reduce the amount of "boilerplate" code that is included in common tasks like querying a database, parsing an xml file, or searching through a data structure, shifting the emphasis onto the actual program logic to help improve readability and maintainability.
C# used to have a mascot
called Andy (named after Anders Hejlsberg). It was retired on 29 Jan 2004.
By design, C# is the programming language that most directly reflects the underlying Common Language Infrastructure
(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
(CIL), or generate any other specific format. Theoretically, a C# compiler could generate machine code like traditional compilers of C++ or Fortran
.
Some notable features of C# that distinguish it from C and C++ (and Java, where noted) are:
Common Type System (CTS)
C# has a unified type system. This unified type system is called Common Type System
(CTS).
A unified type system implies that all types, including primitives such as integers, are subclasses of the class. For example, every type inherits a method.
Instances of value types do not have referential identity nor 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 , 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 an explicit default (parameterless) constructor. Examples of value types are all primitive types, such as (a signed 32-bit integer), (a 32-bit IEEE floating-point number), (a 16-bit Unicode code unit), and (identifies a specific point in time with nanosecond precision). Other examples are (enumerations) and (user defined structures).
In contrast, reference types have the notion of referential identity - each instance of a 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 ). 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 or ). Examples of reference types are (the ultimate base class for all other C# classes), (a string of Unicode characters), and (a base class for all C# arrays).
Both type categories are extensible with user-defined types.
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
. A boxed object of type T can only be unboxed to a T (or a nullable T).
Example:
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.
were added to version 2.0 of the C# language. Generics use type parameters, which make it possible to design classes and methods that do not specify the type used until the class or method is instantiated. The main advantage is that one can use generic type parameters to create classes and methods that can be used without incurring the cost of runtime casts or boxing operations, as shown here:
// Declare the generic class.
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main
{
// Declare a list of type int.
GenericList list1 = new GenericList;
// Declare a list of type string.
GenericList list2 = new GenericList;
// Declare a list of type ExampleClass.
GenericList list3 = new GenericList;
}
}
Preprocessor
C# features "preprocessor directives" (though it does not have an actual preprocessor) based on the C preprocessor
that allow programmers to define symbols, but not macros. Conditionals such as , , and are also provided. Directives such as give hints to editors for code folding
.
public class Foo
{
#region Constructors
public Foo {}
public Foo(int firstParam) {}
#endregion
#region Procedures
public void IntBar(int firstParam) {}
public void StrBar(string firstParam) {}
public void BoolBar(bool firstParam) {}
#endregion
}
Code comments
C# utilizes a double forward slash to indicate the rest of the line is a comment
. This is inherited from C++
.
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 . This is inherited from standard C
.
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
, but based on XML
. Two methods of documentation are currently supported by the C# compiler
.
Single-line documentation comments, such as those commonly found in Visual Studio
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
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 from this code block:
/**
*
A summary of the method. */
Syntax for documentation comments and their XML
markup is defined in a non-normative annex of the ECMA
C# standard. The same standard also defines rules for processing of such comments, and their transformation to a plain XML
document with precise rules for mapping of CLI
identifiers to their related documentation elements. This allows any C# IDE
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
(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:
using System;
class Program
{
static void Main
{
Console.WriteLine("Hello world!");
}
}
The effect is to write the following text to the output console:
Hello world!
Each line has a purpose:
using System;
The above line of code tells the compiler to use
class Program
Above is a class
definition. Everything between the following pair of braces describes .
static void Main
This declares the class member method where the program begins execution. The .NET runtime calls the method. (Note: may also be called from elsewhere, like any other method, e.g. from another method of .) The keyword makes the method accessible without an instance of . Each console application's entry point must be declared . Otherwise, the program would require an instance, but any instance would require a program. To avoid that irresolvable circular dependency
, C# compilers processing console applications
(like that above) report an error, if there is no method. The keyword declares that has no return value.
Console.WriteLine("Hello world!");
This line writes the output. is a static class in the namespace. It provides an interface to the standard input, output, and error streams for console applications. The program calls the method , which displays on the console a line with the argument, the string .
A GUI
example:
using System.Windows.Forms;
class Program
{
static void Main
{
MessageBox.Show("Hello world!");
}
}
Standardization and licensing
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:2003 - 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
(similar to C++ templates
).
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.
The C# language definition and the CLI
are standardized under ISO and Ecma
standards that provide reasonable and non-discriminatory licensing
protection from patent claims. However, Microsoft uses C# and the CLI in its Base Class Library
(BCL) that is the foundation of its proprietary .NET framework, and which provides a variety of non-standardized classes (extended I/O
, GUI
, Web service
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
that releases patent rights to the public, but there is some concern and debate as to whether there are additional aspects patented by Microsoft that are not covered, which may deter independent implementations of the full framework.
Microsoft has agreed not to sue open source developers for violating patents in non-profit projects for the part of the framework that is covered by the OSP. Microsoft has also agreed not to enforce patents relating to Novell
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
). 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
.
In a note posted on the Free Software Foundation
's news website in June 2009, Richard Stallman
warned that he believes that "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
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
were not covered by this promise.
Implementations
The reference C# compiler is Microsoft Visual C#
.
Other C# compilers exist, often including an implementation of the Common Language Infrastructure
and the .NET class libraries up to .NET 2.0:
See also
External links
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....
encompassing strong typing, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...
, declarative
Declarative programming
In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than...
, 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
In a broad definition, 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 using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
(class-based
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
), and component-oriented
Component-based software engineering
Component-based software engineering is a branch of software engineering that emphasizes 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 an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...
within its .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
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 global reach and activities...
(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 February 23, 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 and standardized by ISO and ECMA 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 most recent version is C# 4.0
C Sharp 4.0
C# 4.0 is the latest version of the C# programming language, which was released on April 11, 2010. Microsoft has released the 4.0 runtime and development environment Visual Studio 2010...
, which was released on April 12, 2010.
Design goals
The ECMA standard lists these design goals for C#:- C# language 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 checkingBounds checkingIn 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 collectionGarbage collection (computer science)In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
. 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 internationalizationInternationalization and localizationIn computing, internationalization and localization are means of adapting computer software to different languages, regional differences and technical requirements of a target market...
is very important. - C# is intended to be suitable for writing applications for both hosted and embedded systemEmbedded systemAn embedded system is a computer system designed for specific control functions within a larger system. often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal...
s, ranging from the very large that use sophisticated operating systemOperating systemAn operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
s, down to the very small having dedicated functions. - Although C# applications are intended to be economical with regard to memory and processing powerClock rateThe clock rate typically refers to the frequency that a CPU is running at.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 circuitry into a corresponding square wave...
requirements, the language was not intended to compete directly on performance and size with C, C++ or assembly language.
Name
The name "C sharp" was inspired by musical notationMusical notation
Music notation or musical notation is any system that represents aurally perceived music, through the use of written symbols.-History:...
where a sharp
Sharp (music)
In music, sharp, dièse , or diesis means higher in pitch and the sharp symbol raises a note by a half tone. Intonation may be flat, sharp, or both, successively or simultaneously...
indicates that the written note should be made a semitone
Semitone
A semitone, also called a half step or a half tone, is the smallest musical interval commonly used in Western tonal music, and it is considered the most dissonant when sounded harmonically....
higher in pitch
Pitch (music)
Pitch is an auditory perceptual property that allows the ordering of sounds on a frequency-related scale.Pitches are compared as "higher" and "lower" in the sense associated with musical melodies,...
. 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 an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, where "++" indicates that a variable should be incremented by 1.
Due to technical limitations of display (standard fonts, browsers, etc.) and the fact that the sharp symbol 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, in some countries, the designation of a number...
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
Visual J# |sharp]]') programming language is a discontinued transitional language for programmers of Java and Visual J++ languages, so they may use their existing knowledge and applications on .NET Framework....
(a .NET language also designed by Microsoft that 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
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...
), and the functional programming
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...
language 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 by Bertrand Meyer and Eiffel Software. The design of the language is closely connected with the Eiffel programming method...
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 licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...
and other GNOME
GNOME
GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. It is 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 Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...
) and Qt# (a .NET language binding for the Qt toolkit
Qt (toolkit)
Qt is a cross-platform application framework that is widely used for developing application software with a graphical user interface , and also used for developing non-GUI programs such as command-line tools and consoles for servers...
).
History
During the development of the .NET Framework, the class librariesBase 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 a term coined by Microsoft to identify computer program code that requires and will only execute under the "management" of a Common Language Runtime virtual machine ....
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 on CP/M, CP/M-86, and DOS, developed by Borland under Philippe Kahn's leadership...
, Embarcadero Delphi (formerly CodeGear Delphi and Borland Delphi), and Visual J++
Visual J++
Visual J++ was Microsoft's specific implementation of Java. Syntax, keywords, and grammatical conventions were the same as Java's. Microsoft discontinued support of J++ in January 2004, replacing it to a certain extent with J# and C#....
. 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 an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, 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 the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...
(CLR), which, in turn, drove the design of the C# language itself.
James Gosling
James Gosling
James A. Gosling, OC is a computer scientist, best known as the father of the Java programming language.-Education and career:In 1977, Gosling received a B.Sc in Computer Science from the University of Calgary...
, who created the 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...
programming language in 1994, and Bill Joy
Bill Joy
William Nelson Joy , commonly known as Bill Joy, is an American computer scientist. Joy co-founded Sun Microsystems in 1982 along with Vinod Khosla, Scott McNealy and Andy Bechtolsheim, and served as chief scientist at the company until 2003...
, a co-founder of Sun Microsystems, the originator of Java, called C# an "imitation" of Java; Gosling further claimed that "[C# is] sort of Java with reliability, productivity and security deleted." Klaus Kreft and Angelika Langer (authors of a C++ streams book) stated in a blog post that "Java and C# are almost identical programming languages. Boring repetition that lacks innovation," "Hardly anybody will claim that Java or C# are revolutionary programming languages that changed the way we write programs," and "C# borrowed a lot from Java - and vice versa. Now that C# supports boxing and unboxing, we'll have a very similar feature in Java."
Anders Hejlsberg has argued that C# is "not a Java clone" and is "much closer to C++" in its design.
Since the release of C# 2.0 in November of 2005, the C# and Java languages have evolved on increasingly divergent trajectories, becoming somewhat less similar. One of the first major departures came with the addition of generics to both languages, with vastly different implementations. C# makes use of reification
Reification (computer science)
Reification is the process by which an abstract idea about a computer program is turned into an explicit data model or other object created in a programming language. A computable/addressable object — a resource — is created in a system as a proxy for a non computable/addressable object...
to provide "first-class" generic objects that can be used like any other class, with code generation performed at class-load time. By contrast, Java's generics are essentially a language syntax feature, and they do not affect the generated byte code, because the compiler performs type erasure
Type erasure
In programming languages, type erasure refers to the compile-time process by which explicit type annotations are removed from a program, before it is executed at run-time. An operational semantics that does not require programs to be accompanied by types is called a type-erasure semantics, to be...
on the generic type information after it has verified its correctness.
Furthermore, C# has added several major features to accommodate functional-style programming, culminating in their LINQ
LINQ
Linq is a word-based card game from Endless Games, introduced at the American International Toy Fair in 2005.Game play requires at least four players, two of whom are dealt cards with the same word, while the others receive blanks. The goal is to gain points by correctly naming the players with...
extensions released with C# 3.0 and its supporting framework of lambda expressions, extension method
Extension method
An Extension method is a new language feature of C# starting with the 3.0 specification, as well as Visual Basic.NET starting with 9.0 and Oxygene with 2.0. Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying...
s, and anonymous classes. These features enable C# programmers to use functional programming techniques, such as closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
, when it is advantageous to their application. The LINQ extensions and the functional imports help developers reduce the amount of "boilerplate" code that is included in common tasks like querying a database, parsing an xml file, or searching through a data structure, shifting the emphasis onto the actual program logic to help improve readability and maintainability.
C# used to have a mascot
Mascot
The term mascot – defined as a term for any person, animal, or object thought to bring luck – colloquially includes anything used to represent a group with a common public identity, such as a school, professional sports team, society, military unit, or brand name...
called Andy (named after Anders Hejlsberg). It was retired on 29 Jan 2004.
Versions
In the course of its development, the C# language has gone through several versions:Version | Language specification | Date | .NET Framework .NET Framework The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability... |
Visual Studio | ||
---|---|---|---|---|---|---|
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 global reach and activities... |
ISO/IEC | Microsoft | ||||
C# 1.0 | December 2002 | April 2003 | January 2002 | January 2002 | .NET Framework 1.0 | Visual Studio .NET 2002 |
C# 1.2 | October 2003 | April 2003 | .NET Framework 1.1 | Visual Studio .NET 2003 | ||
C# 2.0 C Sharp 2.0 The programming language C# introduces several new features in version 2.0 . These include:- Partial class :... |
June 2006 | September 2006 | September 2005The Microsoft C# 2.0 specification document only contains the new 2.0 features. For older features use the 1.2 specification above. | November 2005 | .NET Framework 2.0 | Visual Studio 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... |
colspan="2" rowspan="2" , no ECMA and ISO/IEC specifications exist for C# 3.0 and 4.0. | August 2007 | November 2007 | .NET Framework 2.0 (Except LINQ/Query Extensions) http://www.danielmoth.com/Blog/using-c-30-from-net-20.aspx .NET Framework 3.0 (Except LINQ/Query Extensions) http://www.danielmoth.com/Blog/using-c-30-from-net-20.aspx .NET Framework 3.5 |
Visual Studio 2008 Visual Studio 2010 |
|
C# 4.0 C Sharp 4.0 C# 4.0 is the latest version of the C# programming language, which was released on April 11, 2010. Microsoft has released the 4.0 runtime and development environment Visual Studio 2010... |
April 2010 | April 2010 | .NET Framework 4 | Visual Studio 2010 |
C# 2.0 | C# 3.0 | C# 4.0 | C# 5.0 (planned) | |
---|---|---|---|---|
Features added |
|
|
|
|
Distinguishing features
- 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 and standardized by ISO and ECMA 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 defined by the Common Language Infrastructure specification and is used by the .NET Framework and Mono...
(CIL), or generate any other specific format. Theoretically, a C# compiler could generate machine code like traditional compilers of C++ or Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...
.
Some notable features of C# that distinguish it from C and C++ (and Java, where noted) are:
- It has 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 shadowingVariable shadowingIn 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 data type, . Statements that take conditions, such as and , require an expression of a type that implements the operator, such as the boolean type. While C++ also has a boolean type, it can be freely converted to and from integers, and expressions such as require only that is convertible to bool, allowing 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 can prevent certain types of common programming mistakes in C or C++ such as
(a = b)
(use of assignment=
instead of equality).
- 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 that 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 type, but it cannot dereference them.
- Managed memory cannot be explicitly freed; instead, it is automatically garbage collected. Garbage collection addresses the problem of memory leakMemory leakA memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...
s by freeing the programmer of responsibility for releasing memory that is no longer needed. - In addition to the construct to handle exceptions, C# has a construct to guarantee execution of the code in the block.
- Multiple inheritanceMultiple inheritanceMultiple inheritance is a feature of some object-oriented computer 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 and simplify architectural requirements throughout CLI. - C#, like C++, but unlike Java, supports operator overloadingOperator overloadingIn object oriented computer programming, operator overloading—less commonly known as operator ad-hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments...
.
- C# is more type safeType safetyIn computer science, type safety is the extent to which a programming language discourages or prevents type errors. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types...
than C++. The only implicit conversions by default are those that are considered safe, such as widening of integers. This is enforced at compile-time, during JITJust-in-time compilationIn computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...
, and, in some cases, at runtime. No implicit conversions occur 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 constructorCopy constructorA copy constructor is a special constructor in the C++ programming language creating 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. Starting with version 4.0, C# supports a "dynamic" data type that enforces type checking at runtime only. - EnumerationEnumerated typeIn 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 scopeScope (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 propertiesProperty (programming)A property, in some object-oriented programming languages, 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 sugarSyntactic sugarSyntactic sugar is a computer science term that refers to syntax within a programming language that is designed to make things easier to read or to express....
for a common pattern in which a pair of methods, accessor (getter) and mutator (setter)Mutator methodIn 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 attributeAttribute (computing)In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such....
of a class. - Full type reflectionReflection (computer science)In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....
and discovery is available. - Checked exceptions are not present in C# (in contrast to Java). This has been a conscious decision based on the issues of scalability and versionability.
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 class. For example, every type inherits a method.
Categories of data types
CTS separates data types into two categories:- Value types
- Reference types
Instances of value types do not have referential identity nor 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 , 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 an explicit default (parameterless) constructor. Examples of value types are all primitive types, such as (a signed 32-bit integer), (a 32-bit IEEE floating-point number), (a 16-bit Unicode code unit), and (identifies a specific point in time with nanosecond precision). Other examples are (enumerations) and (user defined structures).
In contrast, reference types have the notion of referential identity - each instance of a 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 ). 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 or ). Examples of reference types are (the ultimate base class for all other C# classes), (a string of Unicode characters), and (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
Type conversion
In computer science, type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies or type representations...
. A boxed object of type T can only be unboxed to a T (or a nullable T).
Example:
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.
Generics
GenericsGeneric programming
In a broad definition, 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...
were added to version 2.0 of the C# language. Generics use type parameters, which make it possible to design classes and methods that do not specify the type used until the class or method is instantiated. The main advantage is that one can use generic type parameters to create classes and methods that can be used without incurring the cost of runtime casts or boxing operations, as shown here:
// Declare the generic class.
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main
{
// Declare a list of type int.
GenericList
// Declare a list of type string.
GenericList
// Declare a list of type ExampleClass.
GenericList
}
}
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 and C++ computer programming languages. 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 , , and are also provided. Directives such as 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...
.
public class Foo
{
#region Constructors
public Foo {}
public Foo(int firstParam) {}
#endregion
#region Procedures
public void IntBar(int firstParam) {}
public void StrBar(string firstParam) {}
public void BoolBar(bool firstParam) {}
#endregion
}
Code comments
C# utilizes a double forward slash to indicate the rest of the line is a comment
Comment (computer programming)
In computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program. Those annotations are potentially significant to programmers but typically ignorable to compilers and interpreters. Comments are usually...
. This is inherited from C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
.
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 . This is inherited from standard C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
.
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 automatically generate...
, but based on XML
Extensible Markup Language
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis 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 programming 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 is 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 description of the parameter.
///
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 .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
1.1 release. These comments are designated by a starting forward slash/asterisk/asterisk and ending asterisk/forward slash .
public class Foo
{
/**
* A description of the parameter.
*
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 from this code block:
/**
*
A summary of the method.
Syntax for documentation comments and their XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis 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 global reach and activities...
C# standard. The same standard also defines rules for processing of such comments, and their transformation to a plain XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
document with precise rules for mapping of CLI
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft and standardized by ISO and ECMA 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 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 and standardized by ISO and ECMA 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:
using System;
class Program
{
static void Main
{
Console.WriteLine("Hello world!");
}
}
The effect is to write the following text to the output console:
Hello world!
Each line has a purpose:
using System;
The above line of code tells the compiler to use
System
as a candidate prefix for types used in the source code. In this case, when the compiler sees use of the Console
type later in the source code, it tries to find a type named Console
, first in the current assembly, followed by all referenced assemblies. In this case the compiler fails to find such a type, since the name of the type is actually System.Console
. The compiler then attempts to find a type named System.Console
by using the System
prefix from the statement, and this time it succeeds. The statement allows the programmer to state all candidate prefixes to use during compilation instead of always using full type names.class Program
Above is a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
definition. Everything between the following pair of braces describes .
static void Main
This declares the class member method where the program begins execution. The .NET runtime calls the method. (Note: may also be called from elsewhere, like any other method, e.g. from another method of .) The keyword makes the method accessible without an instance of . Each console application's entry point must be declared . 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
Console application
A console application is a computer program designed to be used via a text-only computer interface, such as a text terminal, the command line interface of some operating systems or the text-based interface included with most Graphical User Interface operating systems, such as the Win32 console in...
(like that above) report an error, if there is no method. The keyword declares that has no return value.
Console.WriteLine("Hello world!");
This line writes the output. is a static class in the namespace. It provides an interface to the standard input, output, and error streams for console applications. The program calls the method , which displays on the console a line with the argument, the string .
A GUI
Gui
Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...
example:
using System.Windows.Forms;
class Program
{
static void Main
{
MessageBox.Show("Hello world!");
}
}
Standardization and licensing
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
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 global reach and activities...
.
In December 2001, ECMA released ECMA-334 C# Language Specification. C# became an ISO standard in 2003 (ISO/IEC 23270:2003 - 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
In a broad definition, 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.
The C# language definition and the CLI
Common Language Infrastructure
The Common Language Infrastructure is an open specification developed by Microsoft and standardized by ISO and ECMA 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 that provide reasonable and non-discriminatory licensing
Reasonable and Non Discriminatory Licensing
Reasonable and non-discriminatory licensing is a type of licensing typically used during standardization processes. When joining a standardization body, companies normally agree that if they receive any patents on technologies which become essential to the standard they agree to allow other...
protection from patent claims. However, 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) that 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 .NET Framework, providing access to native Microsoft Windows interface elements by wrapping the extant Windows API in managed code...
, Web service
Web service
A Web service is a method of communication between two electronic devices over the web.The W3C defines a "Web service" 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 a promise by Microsoft, published in September 2006, to not assert legal rights over certain Microsoft patents on implementations of an included list of technologies....
that releases patent rights to the public, but there is some concern and debate as to whether there are additional aspects patented by Microsoft that are not covered, which may deter independent implementations of the full framework.
Microsoft has agreed not to sue open source developers for violating patents in non-profit projects for the part of the framework that is covered by the OSP. Microsoft has also agreed not to enforce patents relating to Novell
Novell
Novell, Inc. is a multinational software and services company. It is a wholly owned subsidiary of The Attachmate Group. It specializes in network operating systems, such as Novell NetWare; systems management solutions, such as Novell ZENworks; and collaboration solutions, such as Novell Groupwise...
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, pronounced , is a free and open source project led by Xamarin 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
Moonlight (runtime)
Moonlight is a free and open source implementation of Microsoft's Silverlight for Linux and other Unix based operating systems, developed by the Mono Project...
, which depends on Mono, provided it is obtained through Novell
Novell
Novell, Inc. is a multinational software and services company. It is a wholly owned subsidiary of The Attachmate Group. It specializes in network operating systems, such as Novell NetWare; systems management solutions, such as Novell ZENworks; and collaboration solutions, such as Novell Groupwise...
.
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 create, distribute and modify computer software...
's news website in June 2009, Richard Stallman
Richard Stallman
Richard Matthew Stallman , often shortened to 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 that "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 create, 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, pronounced , is a free and open source project led by Xamarin 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# 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 exist, Visual C# is...
.
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 and standardized by ISO and ECMA 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:
- The MonoMono (software)Mono, pronounced , is a free and open source project led by Xamarin 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 sourceOpen sourceThe term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
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 3.5. As of Mono 2.6, no plans exist to implement WPFWindows Presentation FoundationDeveloped by Microsoft, the Windows Presentation Foundation is a computer-software graphical subsystem for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Rather than relying on the older GDI...
; WFWindows Workflow FoundationWindows Workflow Foundation is a Microsoft technology that provides an API, an in-process workflow engine, and a rehostable designer to implement long-running processes as workflows within .NET applications...
is planned for a later release; and there are only partial implementations of LINQ to SQL and WCFWindows Communication FoundationThe Windows Communication Foundation , previously known as "Indigo", is an application programming interface in the .NET Framework for building connected, service-oriented applications.-The architectures:...
. - The DotGNUDotGNUDotGNU is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework by Free Software Foundation...
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). - Microsoft's Rotor project (currently called Shared Source Common Language InfrastructureShared Source Common Language InfrastructureThe 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 sourceShared sourceShared source is an umbrella term covering some of Microsoft's legal mechanisms for software source code distribution. Microsoft's Shared Source Initiative, launched in May 2001, includes a spectrum of technologies and licenses...
implementation of the CLR runtime and a C# compiler, and a subset of the required Common Language InfrastructureCommon Language InfrastructureThe Common Language Infrastructure is an open specification developed by Microsoft and standardized by ISO and ECMA 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 DotNetAnywhere Micro Framework-like Common Language RuntimeCommon Language RuntimeThe Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...
is targeted at embedded systems, and supports almost all C# 2.0 specifications. It is licensed under the MIT LicenseMIT LicenseThe MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...
conditions, is implemented in CC (programming language)C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and directed towards embedded devices.
See also
- .NET Framework Standardization and licensing
- BorlandBorlandBorland Software Corporation is a software company first headquartered in Scotts Valley, California, Cupertino, California and finally Austin, Texas. It is now a Micro Focus subsidiary. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn.-The 1980s:...
Turbo C SharpTurbo C SharpTurbo 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.... - C# syntaxC Sharp syntaxThis 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. There are certain standard naming conventions to follow when selecting names for elements.An...
- Comparison of Java and C#
- Microsoft Visual StudioMicrosoft Visual StudioMicrosoft Visual Studio is an integrated development environment from Microsoft. It is 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# - Mono and Microsoft’s patents
- MonoDevelopMonoDevelopMonoDevelop 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 frameworks...
, an open-source C# IDE for LinuxLinuxLinux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
, WindowsMicrosoft WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
and Mac OS XMac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems... - MorfikMorfikMorfik Technology Pty Ltd., an Australian company, is the developer of Morfik, a set of visual designers, compilers and a Framework combined in an Integrated development environment aimed at developing Ajax applications in a high-level language such as Java, C#, BASIC or Object Pascal. Morfik...
C#, a C# to JavaScript compiler complete with IDE and framework for Web application development. - Oxygene
- SharpDevelopSharpDevelopSharpDevelop is a free and open source integrated development environment for the Microsoft .NET, Mono, Gtk# and Glade# platforms, and supports development in C#, Visual Basic .NET, Boo, F#, IronPython and IronRuby programming languages.It was designed as a free and lightweight alternative to...
, an open-source C# IDE for WindowsMicrosoft WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal... - Sing#Sing sharpSing# 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...
External links
- C# Language (MSDN)
- C# Language Specification (hyperlinked)
- C# Programming Guide (MSDN)
- C# Specification (MSDN)
- Download C# Express
- ISO C# Language Specification.
- Microsoft Visual C# .NET
- QuickSharp, an open-source, minimalist C# IDE for WindowsMicrosoft WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...