C Sharp (programming language): Difference between revisions
Made some slight grammar changes. Tag: Reverted |
m Reverted 1 edit by 143.105.119.23 (talk) to last revision by John of Reading |
||
Line 1: | Line 1: | ||
{{Short description| |
{{Short description|Programming language}} |
||
{{Correct title| |
{{Correct title|title=C#|reason=#}} |
||
<!-- Per Ecma, "C#" (i.e. not "C♯") is the standard spelling of the name of the language. See "Name" section and talk page. --> |
|||
{{Use mdy dates|dte=Apil 2020}} |
|||
{{Infobox programmn laguage |
|||
{{Use mdy dates|date= April 2020}} |
|||
{{Infobox programming language |
|||
| name = C# |
| name = C# |
||
| logo = |
| logo = C_Sharp_Logo_2023.svg |
||
| logo size = 165px |
| logo size = 165px |
||
| |
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[Structured programming|structured]], [[Imperative programming|imperative]], [[Object-oriented programming|object-oriented]], [[Event-driven programming|event-driven]], [[The Task-based Asynchronous Pattern|task-driven]], [[Functional programming|functional]], [[Generic programming|generic]], [[Reflective programming|reflective]], [[Concurrent computing|concurrent]] |
||
| |
| family = [[C (programming language)|C]] |
||
| |
| year = {{start date and age|2000}}<ref>{{Cite web | url=https://www.infoq.com/minibooks/emag-c-sharp-preview | title=InfoQ eMag: A Preview of C# 7 | access-date=November 11, 2016 | archive-date=April 24, 2023 | archive-url=https://web.archive.org/web/20230424033239/https://www.infoq.com/minibooks/emag-c-sharp-preview/ | url-status=live }}</ref> |
||
| |
| designer = [[Anders Hejlsberg]] ([[Microsoft]]) |
||
| |
| developer = Mads Torgersen ([[Microsoft]]) |
||
| |
| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}} |
||
| |
| latest release date = {{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}} |
||
| |
| latest preview version = {{wikidata|property|edit|reference|P548=Q3295609|P348}} |
||
| |
| latest preview date = {{start date and age|{{wikidata|qualifier|single|P548=Q3295609|P348|P577}}}} |
||
| typing = [[ |
| typing = [[Static typing|Static]], [[Dynamic typing|dynamic]],<ref name="dynamic" /> [[Strong and weak typing|strong]], [[Type system#Safely and unsafely typed systems|safe]], [[Nominative type system|nominative]], [[Type inference|partly inferred]] |
||
| memory |
| memory management = [[Garbage collection (computer science)|automatic memory management]] |
||
| |
| implementations = [[Microsoft Visual C Sharp|Visual C#]], [[.NET]], [[Mono (software)|Mono]], [[Universal Windows Platform]]<br/>'''Discontinued''': [[.NET Framework]], [[DotGNU]] |
||
| |
| dialects = [[Cω]], [[Polyphonic C Sharp|Polyphonic C#]], [http://ecsharp.net Enhanced C#] |
||
| |
| influenced_by = [[C++]],<ref name="influenced by CPP" /> [[Cω]], [[Eiffel (programming language)|Eiffel]], [[F Sharp (programming language)|F#]],{{efn|for async}} [[Haskell]], [[Scala (programming language)|Scala]], [[Icon (programming language)|Icon]], [[J Sharp|J#]], [[Visual J++|J++]], [[Java (programming language)|Java]],<ref name="influenced by CPP" /> [[JavaScript]]<!--var-->, [[ML (programming language)|ML]], [[Modula-3]], [[Object Pascal]],<ref name="influenced by op" /> [[Visual Basic|VB]] |
||
| |
| influenced = [[Chapel (programming language)|Chapel]],<ref name="chplspec">{{cite web|title=Chapel spec (Acknowledgments)|url=http://chapel.cray.com/spec/spec-0.98.pdf|date=2015-10-01|access-date=2016-01-14|publisher=Cray Inc|archive-date=February 5, 2016|archive-url=https://web.archive.org/web/20160205114946/http://chapel.cray.com/spec/spec-0.98.pdf|url-status=dead}}</ref> [[Clojure]],<ref>{{cite web |url=http://www.codequarterly.com/2011/rich-hickey|archive-url=https://web.archive.org/web/20170111184835/http://www.codequarterly.com/2011/rich-hickey|url-status=dead|archive-date=2017-01-11|title=Rich Hickey Q&A by Michael Fogus|access-date=2017-01-11}}</ref> [[Crystal (programming language)|Crystal]],<ref name="rel_0.18.0">{{cite web |
||
| url = http:// |
| url = http://crystal-lang.org/2016/06/14/crystal-0.18.0-released.html#comment-2732771703 |
||
| title = |
| title = Crystal 0.18.0 released! |
||
| last = |
| last = Borenszweig |
||
| first = Ary |
| first = Ary |
||
| date = June 14, 2016 |
| date = June 14, 2016 |
||
| quote = It's |
| quote = It's heavily inspired by Ruby, and other languages (like C#, Go and Python). |
||
| |
| access-date = August 7, 2017 |
||
| |
| archive-date = December 25, 2018 |
||
| |
| archive-url = https://web.archive.org/web/20181225175315/https://crystal-lang.org/2016/06/14/crystal-0.18.0-released.html#comment-2732771703 |
||
| url-status = live |
| url-status = live |
||
}} |
}}</ref> [[D (programming language)|D]], [[J Sharp|J#]], [[Dart (programming language)|Dart]],<ref>{{cite web|title=Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013|website = [[YouTube]]| date=May 16, 2013 |url=https://www.youtube.com/watch?v=huawCRlo9H4&t=30m10s |archive-url=https://ghostarchive.org/varchive/youtube/20211221/huawCRlo9H4 |archive-date=2021-12-21 |url-status=live|access-date=22 December 2013}}{{cbignore}}</ref> [[F Sharp (programming language)|F#]], [[Hack (programming language)|Hack]], [[Java (programming language)|Java]],<ref>Java 5.0 added several new language features (the [[foreach loop|enhanced for loop]], [[Object type (object-oriented programming)#Autoboxing|autoboxing]], [[variadic function|varargs]] and [[Java annotation|annotations]]), after they were introduced in the similar (and competing) C# language [http://www.barrycornelius.com/papers/java5/] {{Webarchive|url=https://web.archive.org/web/20110319065438/http://www.barrycornelius.com/papers/java5/ |date=March 19, 2011 }} [http://www.levenez.com/lang/] {{Webarchive|url=https://web.archive.org/web/20060107162045/http://www.levenez.com/lang/ |date=January 7, 2006 }}</ref><ref name="influenced" /> [[Kotlin (programming language)|Kotlin]], [[Nemerle]], [[Oxygene (programming language)|Oxygene]], [[Rust (programming language)|Rust]],<ref>{{Cite web |url=https://doc.rust-lang.org/reference/influences.html |title=Influences - The Rust Reference |website=The Rust Reference |access-date=2023-04-18 |archive-date=January 26, 2019 |archive-url=https://web.archive.org/web/20190126051127/https://doc.rust-lang.org/reference/influences.html |url-status=live }}</ref> [[Swift (programming language)|Swift]],<ref name="lattner2014">{{cite web|url=http://nondot.org/sabre/|title=Chris Lattner's Homepage|last=Lattner|first=Chris|date=2014-06-03|access-date=2020-05-12|publisher=Chris Lattner|quote=The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.|archive-date=December 25, 2018|archive-url=https://web.archive.org/web/20181225175312/http://nondot.org/sabre/|url-status=live}}</ref> [[Vala (programming language)|Vala]], [[TypeScript]] |
||
| platform = [[ |
| platform = [[Common Language Infrastructure]] |
||
| |
| license = {{plainlist| |
||
*[[Roslyn ( |
*[[Roslyn (compiler)|Roslyn]] compiler: [[MIT License|MIT/X11]]<ref name="auto">{{Cite web|url=https://github.com/dotnet/roslyn|title=The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.: dotnet/roslyn|date=November 13, 2019|via=GitHub|access-date=February 13, 2015|archive-date=February 22, 2021|archive-url=https://web.archive.org/web/20210222190922/https://github.com/dotnet/roslyn|url-status=live}}</ref> |
||
*[[.NET Core|.NET Core CLR]]: [[MIT |
*[[.NET Core|.NET Core CLR]]: [[MIT License|MIT/X11]]<ref>{{Cite web|url=https://github.com/dotnet/coreclr|title=CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes.: dotnet/coreclr|date=November 13, 2019|via=GitHub|access-date=March 8, 2017|archive-date=October 14, 2019|archive-url=https://web.archive.org/web/20191014104939/https://github.com/dotnet/coreclr|url-status=live}}</ref> |
||
*[[Mono ( |
*[[Mono (software)|Mono]] compiler: dual [[GPLv3]] and MIT/X11 |
||
*[[DotGNU]]: |
*[[DotGNU]]: dual [[GPL]] and [[LGPL]] |
||
}} |
}} |
||
| file_ext = |
| file_ext = <code>.cs</code>, <code>.csx</code> |
||
| |
| website = {{URL|https://learn.microsoft.com/en-us/dotnet/csharp/}} |
||
| wikibooks = C Sharp |
| wikibooks = C Sharp Programming |
||
}} |
}} |
||
'''C#''' ([[Pronunciation of |
'''C#''' ([[Pronunciation of English|pronounced]]: C-sharp)<!-- Can be altered as a template. --> ({{IPAc-en|,|s|i:|_|'|sh|a:r|p}} {{respell|see|_|SHARP}}){{efn|By convention, a [[number sign]] is used for the second character in normal text; in artistic representations, sometimes a true [[♯|sharp sign]] is used: C♯. However the [[Ecma International|ECMA]] 334 standard states: "The name C# is written as the LATIN CAPITAL LETTER C (U+0043) followed by the NUMBER SIGN # (U+0023)."}} is a [[General-purpose programming language|general-purpose]] [[High-level programming language|high-level]] [[programming language]] supporting multiple [[Programming paradigm|paradigm]]s. C# encompasses static typing,{{sfn|Skeet|2019}}{{rp|4}} [[Strong and weak typing|strong typing]], [[lexically scoped]], [[Imperative programming|imperative]], [[Declarative programming|declarative]], [[Functional programming|functional]], [[Generic programming|generic]],{{sfn|Skeet|2019}}{{rp|22}} [[Object-oriented programming|object-oriented]] ([[Class (computer programming)|class]]-based), and [[Component-based software engineering|component-oriented]] programming disciplines.<ref name="ECMA-334" /> |
||
The principa inventors of the C# programmn language were [[Ander Hejlsberg]], Scot Wiltamuth, and Petr Golde from [[Micrsoft]].<ref name="ECMA-334" /> It was firs widly distrbuted in July 2000<ref name="ECMA-334" /> and was later appoved as an [[internaional standrd]] by [[Ecma Internaional|Ecma]] (ECMA-334) in 2002 and [[Internaional Organiztion for Standardiztion|ISO]]/[[Internaional Electrotehnicl Comission|IEC]] (ISO/IEC 23270 and 20619{{efn|Langage versios 1.0, 2.0, and 5.0 are availble as ISO/IEC 23270. Begiinng with versin 7.0, the specifcaion is availble as ISO/IEC 20619}}) in 2003. Micrsoft introducd C# alog with [[.NET Framewor]] and Micrsoft [[Viusl Studio]], both of whic are techicaly speakng, [[Propietray sftware|cosd-sourc]]. At the tim, Micrsoft had no open-sourc producs. Four yeas later, in 2004, a [[fre and open-sourc]] projec caled Micrsoft [[Mono (sftware)|Mono]] bega, provding a [[cros-platorm]] [[compier]] and [[runtim environmnt]] for the C# programmn language. A decad later, Micrsoft relesed [[Viusl Studio Cod]] (cod editor), [[Roslyn (comiler)|Roslyn]] (comiler), and [[.NET|the unifed .NET platorm]] (sftware framewor), all of whic supor C# and are fre, open-sourc, and cros-platorm. Mono also joned Micrsoft but was not mergd into .NET. |
|||
The principal inventors of the C# programming language were [[Anders Hejlsberg]], Scott Wiltamuth, and Peter Golde from [[Microsoft]].<ref name="ECMA-334" /> It was first widely distributed in July 2000<ref name="ECMA-334" /> and was later approved as an [[international standard]] by [[Ecma International|Ecma]] (ECMA-334) in 2002 and [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] (ISO/IEC 23270 and 20619{{efn|Language versions 1.0, 2.0, and 5.0 are available as ISO/IEC 23270. Beginning with version 7.0, the specification is available as ISO/IEC 20619}}) in 2003. Microsoft introduced C# along with [[.NET Framework]] and Microsoft [[Visual Studio]], both of which are technically speaking, [[Proprietary software|closed-source]]. At the time, Microsoft had no open-source products. Four years later, in 2004, a [[free and open-source]] project called Microsoft [[Mono (software)|Mono]] began, providing a [[cross-platform]] [[compiler]] and [[runtime environment]] for the C# programming language. A decade later, Microsoft released [[Visual Studio Code]] (code editor), [[Roslyn (compiler)|Roslyn]] (compiler), and [[.NET|the unified .NET platform]] (software framework), all of which support C# and are free, open-source, and cross-platform. Mono also joined Microsoft but was not merged into .NET. |
|||
{{As of|Janury 2025|post=,}} the mos recnt stabl versin of the laguage is C# 13.0, whic was relesed in 2024 in .NET 9.0<ref>{{Cite web |las=Dollard |firs=Kathlen |dat=2023-11-14 |title=Anoucing C# 12 |url=htps://devblogs.micrsoft.com/dotne/anoucing-csharp-12/ |aces-date=2023-11-18 |websit=.NET Blog |laguage=en-US |archiv-date=Novemer 18, 2023 |archiv-url=htps://web.arhive.org/web/20231118121012/htps://devblogs.micrsoft.com/dotne/anoucing-csharp-12/ |url-status=liv}}</ref><ref>{{Cite web |las=Seth |firs=Gaurav |dat=2023-11-14 |title=Anoucing .NET 8 |url=htps://devblogs.micrsoft.com/dotne/anoucing-dotne-8/ |aces-date=2023-11-18 |websit=.NET Blog |laguage=en-US |archiv-date=Novemer 19, 2023 |archiv-url=htps://web.arhive.org/web/20231119051129/htps://devblogs.micrsoft.com/dotne/anoucing-dotne-8/ |url-status=liv}}</ref> |
|||
==Desin goals== |
|||
{{As of|January 2025|post=,}} the most recent stable version of the language is C# 13.0, which was released in 2024 in .NET 9.0<ref>{{Cite web |last=Dollard |first=Kathleen |date=2023-11-14 |title=Announcing C# 12 |url=https://devblogs.microsoft.com/dotnet/announcing-csharp-12/ |access-date=2023-11-18 |website=.NET Blog |language=en-US |archive-date=November 18, 2023 |archive-url=https://web.archive.org/web/20231118121012/https://devblogs.microsoft.com/dotnet/announcing-csharp-12/ |url-status=live }}</ref><ref>{{Cite web |last=Seth |first=Gaurav |date=2023-11-14 |title=Announcing .NET 8 |url=https://devblogs.microsoft.com/dotnet/announcing-dotnet-8/ |access-date=2023-11-18 |website=.NET Blog |language=en-US |archive-date=November 19, 2023 |archive-url=https://web.archive.org/web/20231119051129/https://devblogs.microsoft.com/dotnet/announcing-dotnet-8/ |url-status=live }}</ref> |
|||
The Ecma standrd lis thes desin goal for C#:<ref name="ECMA-334">{{cite bok |url=htps://www.ecma-internaional.org/wp-cotnt/uploads/ECMA-334_4th_edtion_june_2006.pdf |title=C# Language Specifcaion |dat=June 2006 |publsher=[[Ecma Internaional]] |edtion=4th |laguage=en-US |aces-date=Janury 26, 2012 |archiv-date=Aprl 21, 2021 |archiv-url=htps://web.arhive.org/web/20210421135433/htps://www.ecma-internaional.org/wp-cotnt/uploads/ECMA-334_4th_edtion_june_2006.pdf |url-status=liv}}</ref> |
|||
==Design goals== |
|||
The Ecma standard lists these design goals for C#:<ref name="ECMA-334">{{cite book |url=https://www.ecma-international.org/wp-content/uploads/ECMA-334_4th_edition_june_2006.pdf |title=C# Language Specification |date=June 2006 |publisher=[[Ecma International]] |edition=4th |language=en-US |access-date=January 26, 2012 |archive-date=April 21, 2021 |archive-url=https://web.archive.org/web/20210421135433/https://www.ecma-international.org/wp-content/uploads/ECMA-334_4th_edition_june_2006.pdf |url-status=live }}</ref> |
|||
* The language is intended to be a simple, modern, general-purpose, [[Object-oriented programming|object-oriented]] programming language. |
|||
* The language, and implementations thereof, should provide support for software engineering principles such as [[Strong and weak typing|strong type]] checking, array [[bounds checking]],{{sfn|Albahari|2022}}{{rp|58–59}} detection of attempts to use [[uninitialized variable]]s, and automatic [[Garbage collection (computer science)|garbage collection]].{{sfn|Albahari|2022}}{{rp|563}} Software robustness, durability, and programmer productivity are important. |
|||
* The language is intended for use in developing [[software components]] suitable for [[Deployment environment|deployment]] in distributed environments. |
|||
* [[Software portability|Portability]] is very important for [[source code]] and [[programmer]]s, especially those already familiar with [[C (programming language)|C]] and [[C++]]. |
|||
* Support for [[internationalization and localization|internationalization]]{{sfn|Albahari|2022}}{{rp|314}} is very important. |
|||
* C# is intended to be suitable for writing applications for both hosted and [[embedded system]]s, ranging from the very large that use sophisticated [[operating system]]s, down to the very small having dedicated functions. |
|||
* Although C# applications are intended to be economical with regard to memory and [[processing power]] requirements, the language was not intended to compete directly on performance and size with C or assembly language.<ref>{{Cite web|title=Design Goals of C#|url=https://www.java-samples.com/showtutorial.php?tutorialid=1425|access-date=2021-10-06|website=www.java-samples.com|archive-date=October 6, 2021|archive-url=https://web.archive.org/web/20211006065344/https://www.java-samples.com/showtutorial.php?tutorialid=1425|url-status=live}}</ref> |
|||
==History== |
|||
{{Multiple image |
|||
| footer = C#'s former logos |
|||
|image1 = Logo C sharp.svg |
|||
|width1 = 90 |
|||
|image2 = C Sharp wordmark.svg |
|||
|width2 = 100 |
|||
}} |
|||
During the development of the [[.NET Framework]], the [[Base Class Library|class libraries]] were originally written using a [[managed code]] compiler system named ''Simple Managed C'' (SMC).<ref>{{cite web |
|||
|url= https://docs.microsoft.com/en-us/archive/blogs/jasonz/couple-of-historical-facts |
|||
|title= Couple of Historical Facts |
|||
|first= Jason |
|||
|last= Zander |
|||
|date= November 22, 2007 |
|||
|access-date= February 23, 2009 |
|||
|archive-date= July 29, 2020 |
|||
|archive-url= https://web.archive.org/web/20200729002618/https://docs.microsoft.com/en-us/archive/blogs/jasonz/couple-of-historical-facts |
|||
|url-status= live |
|||
}}</ref><ref>{{cite web |
|||
|url= http://aspadvice.com/blogs/rbirkby/archive/2006/11/28/What-language-was-ASP.Net-originally-written-in_3F00_.aspx |
|||
|archive-url= https://web.archive.org/web/20160624010356/http://aspadvice.com/blogs/rbirkby/archive/2006/11/28/What-language-was-ASP.Net-originally-written-in_3F00_.aspx |
|||
|archive-date= June 24, 2016 |
|||
|title= What language was ASP.Net originally written in? |
|||
|date= November 28, 2006 |
|||
|first= |
|||
|last= |
|||
|author-link= Scott Guthrie |
|||
|access-date= February 21, 2008 |
|||
}}</ref> In January 1999, [[Anders Hejlsberg]] formed a team to build a new language at the time called COOL, which stood for "[[List of C-family programming languages|C-like]] Object Oriented Language".<ref name="computerworld2008">{{cite magazine |
|||
|url= https://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/ |
|||
|title= The A-Z of Programming Languages: C# |
|||
|first= Naomi |
|||
|last= Hamilton |
|||
|magazine= [[Computerworld]] |
|||
|date= October 1, 2008 |
|||
|access-date= October 1, 2008 |
|||
|archive-url=https://web.archive.org/web/20190518115808/https://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/ |
|||
|archive-date=18 May 2019 |url-status=dead}}</ref> Microsoft had considered keeping the name "COOL(C-like Object Oriented Language)" 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 were ported to C#. |
|||
Hejlsberg is C#'s principal designer and lead architect at Microsoft, and was previously involved with the design of [[Turbo Pascal]], [[Embarcadero Technologies|Embarcadero]] [[Delphi (software)|Delphi]] (formerly [[CodeGear]] Delphi, [[Inprise]] Delphi and [[Borland]] Delphi), and [[Visual J++]]. In interviews and technical papers, he has stated that flaws<ref>{{Cite web |title=Details |url=http://nilsnaegele.com/techreview/Reviews/Details/1 |archive-url=https://web.archive.org/web/20190407173805/http://nilsnaegele.com/techreview/Reviews/Details/1 |archive-date=2019-04-07 |access-date=2019-04-07 |url-status=usurped |website=nilsnaegele.com}}</ref> in most major programming languages (e.g. [[C++]], [[Java (programming language)|Java]], [[Delphi (software)|Delphi]], and [[Smalltalk]]) drove the fundamentals of the [[Common Language Runtime]] (CLR), which, in turn, drove the design of the C# language. |
|||
[[James Gosling]], who created the [[Java (programming language)|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 said that "[C# is] sort of Java with reliability, productivity and security deleted."<ref name="gosling">{{cite web |
|||
|url=https://www.cnet.com/tech/tech-industry/why-microsofts-c-isnt/ |
|||
|title=Why Microsoft's C# isn't |
|||
|publisher=CNET: CBS Interactive |
|||
|year=2002 |
|||
|access-date=September 18, 2023 |
|||
|archive-date=August 14, 2023 |
|||
|archive-url=https://web.archive.org/web/20230814054213/https://www.cnet.com/tech/tech-industry/why-microsofts-c-isnt/ |
|||
|url-status=live |
|||
}}</ref><ref>{{cite web |
|||
|url= https://www.cnet.com/tech/tech-industry/microsofts-blind-spot/ |
|||
|title= Microsoft's blind spot |
|||
|author= Bill Joy |
|||
|publisher= cnet.com |
|||
|date= February 7, 2002 |
|||
|access-date= September 18, 2023 |
|||
|author-link= Bill Joy |
|||
|archive-date= August 14, 2023 |
|||
|archive-url= https://web.archive.org/web/20230814053108/https://www.cnet.com/tech/tech-industry/microsofts-blind-spot/ |
|||
|url-status= live |
|||
}}</ref> |
|||
In July 2000, Hejlsberg said that C# is "not a Java clone" and is "much closer to C++" in its design.<ref name="JohnOsborn">{{Cite news |
|||
|last= Osborn |
|||
|first= John |
|||
|date= August 1, 2000 |
|||
|url= http://windowsdevcenter.com/pub/a/oreilly/windows/news/hejlsberg_0800.html |
|||
|title= Deep Inside C#: An Interview with Microsoft Chief Architect Anders Hejlsberg |
|||
|publisher= O'Reilly Media |
|||
|access-date= November 14, 2009 |
|||
|archive-date= January 9, 2010 |
|||
|archive-url= https://web.archive.org/web/20100109195800/http://windowsdevcenter.com/pub/a/oreilly/windows/news/hejlsberg_0800.html |
|||
|url-status= live |
|||
}}</ref> |
|||
Since the release of C# 2.0 in November 2005, the C# and Java languages have evolved on increasingly divergent trajectories, becoming two quite different languages. One of the first major departures came with the addition of [[Generic programming|generics]] to both languages, with vastly different implementations. C# uses of [[Reification (computer science)|reification]] to provide "first-class" generic objects that can be used like any other class, with [[code generation (compiler)|code generation]] performed at class-load time.<ref>{{cite web |
|||
| url = http://msdn.microsoft.com/en-us/library/512aeb7t.aspx |
|||
| title = Generics (C# Programming Guide) |
|||
| publisher = Microsoft |
|||
| access-date = March 21, 2011 |
|||
| archive-date = August 26, 2011 |
|||
| archive-url = https://web.archive.org/web/20110826233800/http://msdn.microsoft.com/en-us/library/512aeb7t.aspx |
|||
| url-status = live |
|||
}}</ref> |
|||
Furthermore, C# has added several major features to accommodate functional-style programming, culminating in the [[Language Integrated Query|LINQ]] extensions released with C# 3.0 and its supporting framework of [[Anonymous function|lambda expressions]], [[extension method]]s, and [[anonymous type]]s.<ref>{{cite web |
|||
| url = http://msdn.microsoft.com/en-us/library/bb308959.aspx |
|||
| title = LINQ: .NET Language-Integrated Query |
|||
| author = Don Box and Anders Hejlsberg |
|||
| publisher = Microsoft |
|||
| date = February 2007 |
|||
| access-date = March 21, 2011 |
|||
| archive-date = August 24, 2011 |
|||
| archive-url = https://web.archive.org/web/20110824063725/http://msdn.microsoft.com/en-us/library/bb308959.aspx |
|||
| url-status = live |
|||
}}</ref> These features enable C# programmers to use functional programming techniques, such as [[Closure (computer science)|closures]], when it is advantageous to their application. The LINQ extensions and the functional imports help developers reduce the amount of [[boilerplate code]] included in common tasks such as 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.<ref>{{cite web |
|||
| url = http://blog.abodit.com/2010/04/why-functional-programming-is-better-linq-c-sharp-than-procedural-code/ |
|||
| title = Why functional programming and LINQ is often better than procedural code |
|||
| last = Mercer |
|||
| first = Ian |
|||
| publisher = abodit.com |
|||
| date = April 15, 2010 |
|||
| access-date = March 21, 2011 |
|||
| archive-date = July 11, 2011 |
|||
| archive-url = https://web.archive.org/web/20110711124734/http://blog.abodit.com/2010/04/why-functional-programming-is-better-linq-c-sharp-than-procedural-code/ |
|||
| url-status = dead |
|||
}}</ref> |
|||
C# used to have a [[mascot]] called Andy (named after [[Anders Hejlsberg]]). It was retired on January 29, 2004.<ref>{{cite web|url=http://blogs.msdn.com/b/danielfe/archive/2004/01/29/64429.aspx |title=Andy Retires |work=Dan Fernandez's Blog |publisher=Blogs.msdn.com |date=January 29, 2004 |access-date=October 4, 2012|archive-url=https://web.archive.org/web/20160119144858if_/http://blogs.msdn.com/b/danielfe/archive/2004/01/29/64429.aspx|archive-date=January 19, 2016}}</ref> |
|||
C# was originally submitted to the ISO/IEC JTC 1 subcommittee [[ISO/IEC JTC 1/SC 22|SC 22]] for review,<ref>{{cite web |url=http://www.iso.org/iso/iso_technical_committee.html?commid=45202 |title=Technical committees - JTC 1/SC 22 - Programming languages, their environments and system software interfaces |publisher=ISO |access-date=October 4, 2012 |archive-date=September 27, 2012 |archive-url=https://web.archive.org/web/20120927020608/http://www.iso.org/iso/iso_technical_committee.html?commid=45202 |url-status=live }}</ref> under ISO/IEC 23270:2003,<ref>{{cite web |url=http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=36768 |title=ISO/IEC 23270:2003 - Information technology - C# Language Specification |publisher=Iso.org |date=August 23, 2006 |access-date=October 4, 2012 |archive-url=https://web.archive.org/web/20120508100146/http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=36768 |archive-date=May 8, 2012 |url-status=dead }}</ref> was withdrawn and was then approved under ISO/IEC 23270:2006.<ref>{{cite web |url=http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?csnumber=42926 |title=ISO/IEC 23270:2006 - Information technology - Programming languages - C# |publisher=Iso.org |date=January 26, 2012 |access-date=October 4, 2012 |archive-date=December 6, 2010 |archive-url=https://web.archive.org/web/20101206152217/http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?csnumber=42926 |url-status=live }}</ref> The 23270:2006 is withdrawn under 23270:2018 and approved with this version.<ref>{{Cite web|title=SO/IEC 23270:2018 Information technology — Programming languages — C#|url=https://www.iso.org/cms/render/live/en/sites/isoorg/contents/data/standard/07/51/75178.html|access-date=2020-11-26|website=ISO|language=en}}</ref> |
|||
===Name=== |
|||
[[Microsoft]] first used the name C# in 1988 for a variant of the C language designed for incremental compilation.<ref>{{cite web|last1=Mariani|first1=Rico|title=My History of Visual Studio (Part 1) – Rico Mariani's Performance Tidbits|url=https://blogs.msdn.microsoft.com/ricom/2009/10/05/my-history-of-visual-studio-part-1/|website=Rico Mariani's Performance Tidbits|date=October 5, 2009|access-date=May 26, 2018|archive-date=May 27, 2018|archive-url=https://web.archive.org/web/20180527120755/https://blogs.msdn.microsoft.com/ricom/2009/10/05/my-history-of-visual-studio-part-1/|url-status=live}}</ref> That project was not completed, and the name was later reused. |
|||
[[File:Treblecsharp5.svg|thumb|100px|right|[[C♯ (musical note)|C-sharp musical note]]]] |
|||
The name "C sharp" was inspired by the musical notation whereby a [[Sharp (music)|sharp symbol]] indicates that the written note should be made a [[semitone]] higher in [[Pitch (music)|pitch]].<ref>{{cite web |
|||
|url= http://www.jameskovacs.com/blog/CNETHistoryLesson.aspx |
|||
|title= C#/.NET History Lesson |
|||
|first= James |
|||
|last= Kovacs |
|||
|date= September 7, 2007 |
|||
|access-date= June 18, 2009 |
|||
|archive-date= March 6, 2009 |
|||
|archive-url= https://web.archive.org/web/20090306073219/http://jameskovacs.com/blog/CNETHistoryLesson.aspx |
|||
|url-status= dead |
|||
}}</ref> |
|||
This is similar to the language name of [[C++]], where "++" indicates that a variable should be incremented by 1 after being evaluated. The sharp symbol also resembles a [[Typographic ligature|ligature]] of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++.<ref>{{cite magazine |
|||
|url= http://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=2 |
|||
|title= The A-Z of Programming Languages: C# |
|||
|first= Anders |
|||
|last= Hejlsberg |
|||
|magazine= [[Computerworld]] |
|||
|date= October 1, 2008 |
|||
|access-date= June 22, 2014 |
|||
|archive-date= April 2, 2015 |
|||
|archive-url= https://web.archive.org/web/20150402120752/https://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=2 |
|||
|url-status= dead |
|||
}}</ref> |
|||
Due to technical limits of display (standard fonts, browsers, etc.), and most [[keyboard layout]]s lacking a sharp symbol ({{unichar|266F|MUSIC SHARP SIGN|html=|nlink=Sharp (music)}}), the [[number sign]] ({{unichar|0023|NUMBER SIGN|html=}}) was chosen to approximate the sharp symbol in the written name of the programming language.<ref name="MS CSharp FAQ">{{cite web |
|||
|url=http://msdn.microsoft.com/vcsharp/previous/2002/FAQ/default.aspx |
|||
|title=Microsoft C# FAQ |
|||
|publisher=[[Microsoft]] |
|||
|access-date=March 25, 2008 |
|||
|url-status=dead |
|||
|archive-url=https://web.archive.org/web/20060214002638/http://msdn.microsoft.com/vcsharp/previous/2002/FAQ/default.aspx |
|||
|archive-date=February 14, 2006 |
|||
|df=mdy |
|||
}}</ref> |
|||
This convention is reflected in the ECMA-334 C# Language Specification.<ref name="ECMA-334"/> |
|||
The "sharp" suffix has been used by a number of other Microsoft [[.NET]] compatible/compliant languages that are variants of existing languages, including [[J Sharp|J#]] (a .NET language also designed by Microsoft that is derived from [[Java (programming language)|Java]] 1.1), [[A Sharp (.NET)|A#]] (from [[Ada (programming language)|Ada]]), and the [[functional programming]] language [[F Sharp (programming language)|F#]].<ref name="MS FSharp FAQ">{{cite web |
|||
|url=http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/faq.aspx |
|||
|title=F# FAQ |
|||
|publisher=Microsoft Research |
|||
|access-date=June 18, 2009 |
|||
|url-status=dead |
|||
|archive-url=https://web.archive.org/web/20090218222543/http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/faq.aspx |
|||
|archive-date=February 18, 2009 |
|||
|df=mdy |
|||
}}</ref> The original implementation of [[EiffelStudio|Eiffel for .NET]] was called [[EiffelStudio|Eiffel#]],<ref>{{cite web |
|||
|url= http://msdn.microsoft.com/en-us/library/ms973898.aspx |
|||
|title= Full Eiffel on the .NET Framework |
|||
|date= June 2002 |
|||
|first1= Raphael |
|||
|last1= Simon |
|||
|first2= Emmanuel |
|||
|last2= Stapf |
|||
|first3= Bertrand |
|||
|last3= Meyer |
|||
|publisher= [[Microsoft]] |
|||
|access-date= June 18, 2009 |
|||
|archive-date= July 21, 2009 |
|||
|archive-url= https://web.archive.org/web/20090721131102/http://msdn.microsoft.com/en-us/library/ms973898.aspx |
|||
|url-status= live |
|||
}}</ref> a name retired since the full [[Eiffel (programming language)|Eiffel]] language is now supported. The suffix has also been used for [[Library (computing)|libraries]], such as [[Gtk Sharp|Gtk#]] (a .NET [[Wrapper pattern|wrapper]] for [[GTK]] and other [[GNOME]] libraries) and [[Cocoa Sharp|Cocoa#]] (a wrapper for [[Cocoa (API)|Cocoa]]). |
|||
===Versions=== |
|||
Development of the text for standards (beginning with C# 6) is done on [https://github.com/dotnet/csharpstandard GitHub]. C# 7 was submitted to [[Ecma International|Ecma]] and approved in December 2023. As of January 2024, the standard for C# 8 is currently under development, referencing the [https://github.com/dotnet/csharplang/tree/main/proposals approved language proposals]. |
|||
{| class="wikitable" |
|||
|- |
|||
! scope="col" rowspan="2" | C#<br/>version |
|||
! scope="colgroup" colspan="3" | Language specification |
|||
! scope="col" rowspan="2" | Date |
|||
! scope="col" rowspan="2" | .NET |
|||
! scope="col" rowspan="2" | [[Visual Studio]] |
|||
|- |
|||
! scope="col" | [[Ecma International|Ecma]] |
|||
! scope="col" | [[ISO/IEC]] |
|||
! scope="col" | [[Microsoft]] |
|||
|- |
|||
| scope="row" | 1.0 |
|||
| rowspan="2" | ECMA-334:2003, [https://ecma-international.org/wp-content/uploads/ECMA-334_2nd_edition_december_2002.pdf December 2002] |
|||
| rowspan="2" | ISO/IEC 23270:2003, [https://store.accuristech.com/ieee/standards/incits-iso-iec-23270-2003?product_id=1157805 April 2003] |
|||
| [http://download.microsoft.com/download/a/9/e/a9e229b9-fee5-4c3e-8476-917dee385062/CSharp%20Language%20Specification%20v1.0.doc January 2002] |
|||
| January 2002 |
|||
| [[.NET Framework version history#.NET Framework 1.0|.NET Framework 1.0]] |
|||
| [[Visual Studio .NET|Visual Studio .NET 2002]] |
|||
|- |
|||
| scope="row" | 1.1<br/>1.2 |
|||
| [http://download.microsoft.com/download/5/e/5/5e58be0a-b02b-41ac-a4a3-7a22286214ff/csharp%20language%20specification%20v1.2.doc October 2003] |
|||
| April 2003 |
|||
| {{ubl|[[.NET Framework 1.1]]}} |
|||
| [[Visual Studio .NET 2003]] |
|||
|- |
|||
| scope="row" | [[C Sharp 2.0|2.0]]<ref>{{cite web|title=What's new in the C# 2.0 Language and Compiler|url=http://msdn.microsoft.com/en-us/library/7cz8t42e(v=vs.80).aspx|publisher=Microsoft|archive-url = https://web.archive.org/web/20101218191709/http://msdn.microsoft.com/en-us/library/7cz8t42e(v=vs.80).aspx|access-date=11 June 2014|archive-date = December 18, 2010}}</ref> |
|||
| ECMA-334:2006, [https://ecma-international.org/wp-content/uploads/ECMA-334_4th_edition_june_2006.pdf June 2006] |
|||
| ISO/IEC 23270:2006, [http://standards.iso.org/ittf/PubliclyAvailableStandards/c042926_ISO_IEC_23270_2006(E).zip September 2006] |
|||
| [http://download.microsoft.com/download/9/8/f/98fdf0c7-2bbd-40d3-9fd1-5a4159fa8044/csharp%202.0%20specification_sept_2005.doc September 2005]{{efn|The Microsoft C# 2.0 specification document only contains the new 2.0 features. For older features, use the 1.2 specification above.}} |
|||
| November 2005 |
|||
| {{ubl|[[.NET Framework 2.0]]|[[.NET Framework 3.0]]}} |
|||
| [[Visual Studio 2005]]<br />[[Visual Studio 2008]] |
|||
|- |
|||
| scope="row" | [[C Sharp 3.0|3.0]]<ref>{{cite web|last1=Hejlsberg|first1=Anders|last2=Torgersen|first2=Mads|title=Overview of C# 3.0|url=http://msdn.microsoft.com/en-us/library/bb308966.aspx|website=Microsoft Developer Network|date=April 30, 2007|publisher=Microsoft|access-date=11 June 2014|archive-date=June 25, 2014|archive-url=https://web.archive.org/web/20140625123055/http://msdn.microsoft.com/en-us/library/bb308966.aspx|url-status=live}}</ref> |
|||
| colspan="2" rowspan="2" {{no|None}} |
|||
| [http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CSharp%20Language%20Specification.doc August 2007] |
|||
| November 2007 |
|||
| {{ubl|.NET Framework 2.0 (Except LINQ)<ref name="danielmoth1">{{cite web |url=http://www.danielmoth.com/Blog/using-c-30-from-net-20.aspx |title=Using C# 3.0 from .NET 2.0 |publisher=Danielmoth.com |date=May 13, 2007 |access-date=October 4, 2012 |archive-date=September 29, 2012 |archive-url=https://web.archive.org/web/20120929075553/http://www.danielmoth.com/Blog/Using-C-30-From-NET-20.aspx |url-status=live }}</ref>|.NET Framework 3.0 (Except LINQ)<ref name="danielmoth1"/>|[[.NET Framework 3.5]]}} |
|||
| [[Visual Studio 2008]] |
|||
|- |
|||
| scope="row" | [[C Sharp 4.0|4.0]]<ref>{{cite web|last=Hejlsberg|first=Anders|title=Future directions for C# and Visual Basic|url=http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-816T|work=Channel 9 |series=BUILD2011 |publisher=Microsoft |date=September 15, 2011 |access-date=September 21, 2011|archive-date=September 23, 2011|archive-url=https://web.archive.org/web/20110923171150/http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-816T|url-status=dead}}</ref> |
|||
| April 2010 |
|||
| April 2010 |
|||
| {{ubl|[[.NET Framework 4.0|.NET Framework 4]]}} |
|||
| [[Visual Studio 2010]] |
|||
|- |
|||
| scope="row" | 5.0<ref>{{cite web|title=An Introduction to New Features in C# 5.0|url=http://blogs.msdn.com/b/mvpawardprogram/archive/2012/03/26/introduction-of-new-features-in-c-5-0.aspx|website= The Microsoft MVP Award Program Blog |date=26 Mar 2012 |publisher=Microsoft|access-date=11 June 2014|url-status=dead|archive-date=June 4, 2014|archive-url=https://web.archive.org/web/20140604224114/http://blogs.msdn.com/b/mvpawardprogram/archive/2012/03/26/introduction-of-new-features-in-c-5-0.aspx}}</ref> |
|||
| ECMA-334:2017, [https://ecma-international.org/wp-content/uploads/ECMA-334_5th_edition_december_2017.pdf December 2017] |
|||
| ISO/IEC 23270:2018, [https://standards.iso.org/ittf/PubliclyAvailableStandards/c075178_ISO_IEC_23270_2018.zip December 2018] |
|||
| [https://www.microsoft.com/en-us/download/details.aspx?id=7029 June 2013] |
|||
| August 2012 |
|||
| {{ubl|[[.NET Framework 4.5]]}} |
|||
| [[Visual Studio 2012]]<br />[[Visual Studio 2013]] |
|||
|- |
|||
| scope="row" | 6.0<ref>{{cite web|title=Languages features in C# 6 and VB 14 |url=https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14|website=GitHub |publisher=dotnet/roslyn |access-date=13 February 2015|url-status=dead|archive-date=January 12, 2016|archive-url=https://web.archive.org/web/20160112082444/https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14}}</ref> |
|||
| ECMA-334:2022, [https://ecma-international.org/wp-content/uploads/ECMA-334_6th_edition_june_2022.pdf June 2022] |
|||
| {{no|None}} |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/ Draft] |
|||
| July 2015 |
|||
| {{ubl|[[.NET Framework 4.6]]|.NET Core 1.0|.NET Core 1.1}} |
|||
| [[Visual Studio 2015]] |
|||
|- |
|||
| scope="row" | 7.0<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7|title=What's new in C# 7|date=2016-12-21|website=Microsoft Docs |url-status=deviated |archive-url=https://web.archive.org/web/20171101224329/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7 |archive-date= Nov 1, 2017 }}</ref><ref name="new_features_in_7">{{Cite web|title = New Features in C# 7.0|url = https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/|first1 = Mads|last1 = Torgersen|publisher = Microsoft|website = .NET Blog|date = March 9, 2017|access-date = 2017-06-09|archive-date = April 11, 2017|archive-url = https://web.archive.org/web/20170411055800/https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/|url-status = live}}</ref> |
|||
| rowspan=4 | ECMA-334:2023, [https://ecma-international.org/wp-content/uploads/ECMA-334_7th_edition_december_2023.pdf December 2023] |
|||
| rowspan=4 | ISO/IEC 20619:2023, [https://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_IEC%2020619_2023%20ed.1%20-%20id.86347%20Publication%20PDF%20(en).zip September 2023] |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.0/ Specification proposal] |
|||
| March 2017 |
|||
| {{ubl|[[.NET Framework 4.7]]}} |
|||
| [[Visual Studio 2017]] version 15.0<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.0|title=Visual Studio 2017 version 15.0 Release Notes|website=Microsoft Learn|date=April 11, 2023|access-date=2023-04-19|archive-date=April 20, 2023|archive-url=https://web.archive.org/web/20230420021649/https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.0|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 7.1<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1|title=What's new in C# 7.1|website=Microsoft Docs|access-date=2017-10-09|archive-date=October 10, 2017|archive-url=https://web.archive.org/web/20171010054644/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1|url-status=live}}</ref> |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.1/ Specification proposal] |
|||
| August 2017 |
|||
| {{ubl|.NET Core 2.0}} |
|||
| [[Visual Studio 2017]] version 15.3<ref>{{Cite web|url=https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.3|title=Visual Studio 2017 version 15.3 Release Notes|website=Microsoft Learn|date=April 11, 2023 |access-date=2023-04-19 |url-status=live |archive-url= https://web.archive.org/web/20230321003648/https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.3 |archive-date= Mar 21, 2023 }}</ref> |
|||
|- |
|||
| scope="row" | 7.2<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-2|title=What's new in C# 7.2|website=Microsoft Docs|access-date=2017-11-26|archive-date=December 1, 2017|archive-url=https://web.archive.org/web/20171201080837/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-2|url-status=live}}</ref> |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.2/ Specification proposal] |
|||
| November 2017 |
|||
| |
|||
| [[Visual Studio 2017]] version 15.5<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5|title=Visual Studio 2017 version 15.5 Release Notes|website=Microsoft Learn|date=April 11, 2023 |access-date=2023-04-19 |url-status=live |archive-url=https://web.archive.org/web/20230420021650/https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5 |archive-date= Apr 20, 2023 }}</ref> |
|||
|- |
|||
| scope="row" | 7.3<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3|title=What's new in C# 7.3|website=Microsoft Docs|access-date=2018-06-23|archive-date=June 23, 2018|archive-url=https://web.archive.org/web/20180623113321/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3|url-status=live}}</ref> |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.3/ Specification proposal] {{Webarchive|url=https://web.archive.org/web/20210307081157/https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.3/ |date=March 7, 2021 }} |
|||
| May 2018 |
|||
| {{ubl|.NET Core 2.1|.NET Core 2.2|[[.NET Framework 4.8]]}} |
|||
| [[Visual Studio 2017]] version 15.7<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.7|title=Visual Studio 2017 version 15.7 Release Notes|website=Microsoft Learn|date=July 13, 2022|access-date=2023-04-19|archive-date=April 20, 2023|archive-url=https://web.archive.org/web/20230420021650/https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.7|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 8.0<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8|title=What's new in C# 8.0|website=Microsoft Docs|date=March 9, 2023|access-date=April 14, 2019|archive-date=September 6, 2020|archive-url=https://web.archive.org/web/20200906163227/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8|url-status=live}}</ref> |
|||
| colspan="2" rowspan="6" {{no|None}} |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/ Specification proposal] |
|||
| September 2019 |
|||
| {{ubl|.NET Core 3.0|.NET Core 3.1}} |
|||
| [[Visual Studio 2019]] version 16.3<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.3|title=Visual Studio 2019 version 16.3 Release Notes|website=Microsoft Learn|date=April 11, 2023 |access-date=2023-04-19 |url-status=live |archive-url=https://web.archive.org/web/20230420021652/https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.3 |archive-date= Apr 20, 2023 }}</ref> |
|||
|- |
|||
| scope="row" | 9.0<ref>{{Cite web|last=BillWagner|title=What's new in C# 9.0 - C# Guide|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9|access-date=2020-10-15|website=Microsoft Learn|language=en-us|archive-date=September 5, 2020|archive-url=https://web.archive.org/web/20200905125516/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9|url-status=live}}</ref> |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/ Specification proposal] |
|||
| November 2020 |
|||
| {{ubl|.NET 5.0}} |
|||
| [[Visual Studio 2019]] version 16.8<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.8|title=Visual Studio 2019 version 16.8 Release Notes|website=Microsoft Learn|date=April 11, 2023|access-date=2023-04-19|archive-date=April 20, 2023|archive-url=https://web.archive.org/web/20230420021651/https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.8|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 10.0<ref>{{Cite web|title=What's new in C# 10|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10|access-date=2021-11-10|website=Microsoft Learn|language=en-us|archive-date=February 8, 2022|archive-url=https://web.archive.org/web/20220208222424/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10|url-status=live}}</ref> |
|||
| [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/ Specification proposal] |
|||
| November 2021 |
|||
| {{ubl|.NET 6.0}} |
|||
| [[Visual Studio 2022]] version 17.0<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.0|title=Visual Studio 2022 version 17.0 Release Notes|website=Microsoft Learn|access-date=2023-04-19|archive-date=July 16, 2023|archive-url=https://web.archive.org/web/20230716094736/https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.0|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 11.0<ref>{{Cite web|title=What's new in C# 11|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11|access-date=2022-08-08|website=Microsoft Learn|language=en-us|archive-date=August 15, 2022|archive-url=https://web.archive.org/web/20220815142541/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11|url-status=live}}</ref> |
|||
| [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/ Specification proposal] |
|||
| November 2022 |
|||
| {{ubl|.NET 7.0}} |
|||
| [[Visual Studio 2022]] version 17.4<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.4|title=Visual Studio 2022 version 17.4 Release Notes|website=Microsoft Learn|access-date=2023-04-19|archive-date=August 6, 2023|archive-url=https://web.archive.org/web/20230806130647/https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.4|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 12.0<ref>{{Cite web|title=What's new in C# 12|url=https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12|access-date=2023-06-29|website=Microsoft Learn|language=en-us|archive-date=July 20, 2023|archive-url=https://web.archive.org/web/20230720114545/https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12|url-status=live}}</ref> |
|||
| [https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12/ Specification proposal] |
|||
| November 2023 |
|||
| {{ubl|.NET 8.0}} |
|||
| [[Visual Studio 2022]] version 17.8<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.8|title=Visual Studio 2022 version 17.8 Release Notes|website=Microsoft Learn|date=August 13, 2024 |access-date=2024-11-18|archive-date=October 6, 2024|archive-url=https://web.archive.org/web/20241006041528/https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.8|url-status=live}}</ref> |
|||
|- |
|||
| scope="row" | 13.0<ref>{{Cite web|title=What's new in C# 13|url=https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13|access-date=2024-11-18|website=Microsoft Learn|language=en-us|archive-date=November 13, 2024|archive-url=https://web.archive.org/web/20241113030010/https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13|url-status=live}}</ref> |
|||
| [https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13/ Specification proposal] |
|||
| November 2024 |
|||
| {{ubl|.NET 9.0}} |
|||
| [[Visual Studio 2022]] version 17.12<ref>{{Cite web|url=https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes|title=Visual Studio 2022 Release Notes|website=Microsoft Learn|date=November 12, 2024 |access-date=2024-11-18|archive-date=November 12, 2024|archive-url=https://web.archive.org/web/20241112180619/https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes|url-status=live}}</ref> |
|||
|} |
|||
==Syntax== |
|||
{{Main|C Sharp syntax|l1 = C# syntax}} |
|||
{{See also|Syntax (programming languages)}} |
|||
The core syntax of the C# language is similar to that of other C-style languages such as C, Objective-C, C++ and Java, particularly: |
|||
* Semicolons are used to denote the end of a statement. |
|||
* [[Curly brackets]] are used to group statements. Statements are commonly grouped into methods (functions), methods into classes, and classes into [[namespaces]]. |
|||
* Variables are assigned using an [[equals sign]], but compared using [[==|two consecutive equals signs]]. |
|||
* [[Square brackets]] are used with [[Array data structure|arrays]], both to declare them and to get a value at a given index in one of them. |
|||
* "class", "int" and "void" are used to define large-scale (usually main) program functions in scripts most of the time in C-style computer programming languages. |
|||
==Distinguishing features== |
|||
{{See also|Comparison of C Sharp and Java|l1=Comparison of C# and Java}} |
|||
Some notable features of C# that distinguish it from C, C++, and Java where noted, are: |
|||
===Portability=== |
|||
By design, C# is the programming language that most directly reflects the underlying [[Common Language Infrastructure]] (CLI).{{sfn|Novák|Velvart|Granicz|Balássy|2010}} Most of its intrinsic types correspond to value-types implemented by the [[Common Language Infrastructure|CLI (Common Language Infrastructure)]] 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|Common Language Runtime (CLR)]], or generate [[Common Intermediate Language|Common Intermediate Language (CIL)]], or generate any other specific format. Some C# compilers can also generate machine code like traditional compilers of Objective-C, C, C++, Assembly and [[Fortran]].<ref>{{Cite web |author1=stevewhims |author2=mattwojo |date=2022-10-20 |title=Compiling Apps with .NET Native - UWP applications |url=https://learn.microsoft.com/en-us/windows/uwp/dotnet-native/ |access-date=2023-10-27 |website=learn.microsoft.com |language=en-us |archive-date=October 27, 2023 |archive-url=https://web.archive.org/web/20231027220533/https://learn.microsoft.com/en-us/windows/uwp/dotnet-native/ |url-status=live }}</ref><ref>{{Cite web |author1=LakshanF |author2=agocke |author3=Rick-Anderson |author4=gewarren |author5=IEvangelist |author6=MichalStrehovsky |author7=just-a-hriday |author8=mitchdenny |author9=am11 |author10=jkotas |author11=GitHubPang |display-authors=3 |date=2023-09-12 |title=Native AOT deployment overview - .NET |url=https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/ |access-date=2023-10-27 |website=learn.microsoft.com |language=en-us |archive-date=November 11, 2023 |archive-url=https://web.archive.org/web/20231111093836/https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/ |url-status=live }}</ref> |
|||
===Typing=== |
|||
C# supports strongly, implicitly typed variable declarations with the keyword <code>var</code>,{{sfn|Skeet|2019}}{{rp|470}} and implicitly typed arrays with the keyword <code>new[]</code> followed by a collection initializer.{{sfn|Skeet|2019}}{{rp|80}}{{sfn|Albahari|2022}}{{rp|58}} |
|||
Its type system is split into two families: Value types, like the built-in numeric types and user-defined structs, which are automatically handed over as copies when used as parameters, and reference types, including arrays, instances of classes, and strings, which only hand over a pointer to the respective object. Due to their special handling of the equality operator and their [[Immutable object|immutability]], strings will nevertheless behave as if they were values, for all practical purposes. You can even use them as [[Switch statement|case]] labels. Where necessary, value types will be [[Boxing (computer science)|boxed]] automatically.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types#81-general|title=Types/General, part of the official C# documentation|publisher=[[Microsoft]]|access-date=2024-04-06|archive-date=March 29, 2024|archive-url=https://web.archive.org/web/20240329145803/https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types#81-general|url-status=live}}</ref> |
|||
C# supports a strict [[Boolean data type]], <code>bool</code>. Statements that take conditions, such as <code>while</code> and <code>if</code>, require an expression of a type that implements the <code>true</code> 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 <code>if (a)</code> require only that <code>a</code> is convertible to bool, allowing <code>a</code> 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 <code>bool</code> can prevent certain types of programming mistakes such as <code>if (a = b)</code> (use of assignment <code>=</code> instead of equality <code>==</code>). |
|||
C# is more [[Type safety|type safe]] than C++. The only [[implicit conversion]]s by default are those that are considered safe, such as widening of integers. This is enforced at compile-time, during [[Just-in-time compilation|JIT]], 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 constructor]]s and conversion operators, which are both implicit by default. |
|||
C# has explicit support for [[Covariance and contravariance (computer science)|covariance and contravariance]] in generic types,{{sfn|Skeet|2019}}{{rp|144}}{{sfn|Albahari|2022}}{{rp|23}} unlike C++ which has some degree of support for contravariance simply through the semantics of return types on virtual methods. |
|||
[[enumerated type|Enumeration]] members are placed in their own [[Scope (programming)|scope]]. |
|||
The C# language does not allow for 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 [[Variable shadowing|shadow]] variables of the enclosing block, unlike C and C++, but may shadow type-level names. |
|||
<!--NOTE TO EDITORS: Classes do NOT *NEED* to go in a Namespace. Check the spec or try it out yourself before stating otherwise.--> |
|||
===Metaprogramming=== |
|||
[[Metaprogramming]] can be achieved in several ways: |
|||
* [[Reflective programming|Reflection]] is supported through .NET APIs, which enable scenarios such as type metadata inspection and dynamic method invocation. |
|||
* Expression trees<ref>{{Cite web|last=BillWagner|title=Expression Trees (C#)|url=https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/|access-date=2021-05-14|website=Microsoft Learn|language=en-us|archive-date=May 15, 2021|archive-url=https://web.archive.org/web/20210515000042/https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/|url-status=live}}</ref> represent code as an [[abstract syntax tree]], where each node is an expression that can be inspected or executed. This enables dynamic modification of executable code at runtime. Expression trees introduce some [[homoiconicity]] to the language. |
|||
* [[Attribute (computing)|Attributes]], in C# parlance, are [[metadata]] that can be attached to types, members, or entire [[Assembly (programming)|assemblies]], equivalent to [[Java annotation|annotations in Java]]. Attributes are accessible both to the compiler and to code through reflection, allowing them to adjust their behaviour.<ref>{{Cite web|url=https://learn.microsoft.com/en-us/dotnet/api/system.attribute|title=Attribute Class}}</ref> Many of the native attributes duplicate the functionality of GCC's and VisualC++'s platform-dependent preprocessor directives.{{Citation needed|date=March 2022}} |
|||
* <code>System.Reflection.Emit</code> namespace,<ref>{{Cite web |last=dotnet-bot |title=System.Reflection.Emit Namespace |url=https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit?view=net-8.0 |access-date=2023-04-28 |website=learn.microsoft.com |language=en-us |archive-date=April 28, 2023 |archive-url=https://web.archive.org/web/20230428191740/https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit?view=net-8.0 |url-status=live }}</ref> which contains classes that emit metadata and [[Common Intermediate Language|CIL]] (types, assemblies, etc.) at [[Runtime system|runtime]]. |
|||
* [[Roslyn (compiler)|The .NET Compiler Platform (Roslyn)]] provides API access to language compilation services, allowing for the compilation of C# code from within .NET applications. It exposes APIs for syntactic ([[Lexical analysis|lexical]]) analysis of code, [[Semantic analysis (compilers)|semantic analysis]], dynamic compilation to CIL, and code emission.<ref>{{Cite web |last=McAllister |first=Neil |date=2011-10-20 |title=Microsoft's Roslyn: Reinventing the compiler as we know it |url=https://www.infoworld.com/article/2621132/microsoft-s-roslyn--reinventing-the-compiler-as-we-know-it.html |access-date=2022-03-05 |website=InfoWorld |language=en |archive-date=March 5, 2022 |archive-url=https://web.archive.org/web/20220305160503/https://www.infoworld.com/article/2621132/microsoft-s-roslyn--reinventing-the-compiler-as-we-know-it.html |url-status=live }}</ref> |
|||
* Source generators,<ref>{{Cite web|date=2020-04-29|title=Introducing C# Source Generators|url=https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/|access-date=2021-05-14|website=.NET Blog|language=en-US|archive-date=May 7, 2021|archive-url=https://web.archive.org/web/20210507115127/https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/|url-status=live}}</ref> a feature of the Roslyn C# compiler, enable compile time metaprogramming. During the compilation process, developers can inspect the code being compiled with the compiler's [[API]] and pass additional generated C# source code to be compiled. |
|||
===Methods and functions=== |
|||
A ''method'' in C# is a member of a class that can be invoked as a function (a sequence of instructions), rather than the mere value-holding capability of a ''field'' (i.e. [[Class variable|class]] or [[instance variable]]).<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#155-fields|title=Classes/fields, part of the official C# documentation|date=February 7, 2024 }}</ref> As in other syntactically similar languages, such as [[C++]] and [[ANSI C]], the signature of a method is a declaration comprising in order: any optional accessibility keywords (such as <code>private</code>), the explicit specification of its return type (such as <code>int</code>, or the keyword <code>void</code> if no value is returned), the name of the method, and finally, a parenthesized sequence of comma-separated parameter specifications, each consisting of a parameter's type, its formal name and optionally, a default value to be used whenever none is provided. Different from most other languages, [[Evaluation strategy|call-by-reference]] parameters have to be marked both at the function definition and at the calling site, and you can choose between <code>ref</code> and <code>out</code>, the latter allowing handing over an uninitialized variable which will have a definite value on return.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out|title=out (C# Reference)|date=March 30, 2024 }}</ref> Additionally, you can specify a [[Variadic function|variable-sized argument list]] by applying the <code>params</code> keyword to the last parameter.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#params-modifier|title=Method parameters/params modifier, part of the official C# documentation|date=May 21, 2024 }}</ref> Certain specific kinds of methods, such as those that simply get or set a field's value by returning or assigning it, do not require an explicitly stated full signature, but in the general case, the definition of a class includes the full signature declaration of its methods.<ref name="properties">{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#157-properties|title=Classes/properties, part of the official C# documentation|date=February 7, 2024 }}</ref> |
|||
Like C++, and unlike Java, C# programmers must use the scope modifier keyword <code>virtual</code> to allow methods to be [[method overriding|overridden]] by subclasses. Unlike C++, you have to explicitly specify the keyword <code>override</code> when doing so.<ref>{{cite web|title=virtual (C# Reference)|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/virtual|website=Microsoft Learn|date=September 15, 2021|language=en-us|access-date=April 4, 2018|archive-date=August 30, 2018|archive-url=https://web.archive.org/web/20180830073741/https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/virtual|url-status=live}}</ref> This is supposed to avoid confusion between overriding and newly overloading a function (i.e. hiding the former implementation). To do the latter, you have to specify the <code>new</code> keyword.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/new-modifier|title='''new''' modifier, part of the official C# documentation|date=April 12, 2023 }}</ref> You can use the keyword <code>sealed</code> to disallow further overrides for individual methods or whole classes.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-and-class-members |title=Abstract and Sealed Classes and Class Members - C# |date=October 27, 2021 }}</ref> |
|||
''Extension methods'' in C# allow programmers to use static methods as if they were methods from a class's method table, allowing programmers to virtually add instance methods to a class that they feel should exist on that kind of objects (and instances of the respective derived classes).{{sfn|Skeet|2019}}{{rp|103–105}}{{sfn|Albahari|2022}}{{rp|202–203}} |
|||
The type <code>dynamic</code> allows for run-time method binding, allowing for JavaScript-like method calls and run-time [[object composition]].{{sfn|Skeet|2019}}{{rp|114–118}} |
|||
C# has support for strongly-typed [[function pointer]]s via the keyword <code>delegate</code>. Like the [[Qt (software)|Qt]] framework's [[pseudo]]-C++ ''signal'' and ''slot'', C# has semantics specifically surrounding publish-subscribe style events, though C# uses delegates to do so. |
|||
C# offers Java-like <code>synchronized</code> method calls, via the attribute <code>[MethodImpl(MethodImplOptions.Synchronized)]</code>, and has support for [[Mutual exclusion|mutually-exclusive locks]] via the keyword <code>lock</code>. |
|||
===Property=== |
|||
C# supports classes with [[property (programming)|properties]]. The properties can be simple accessor functions with a backing field, or implement arbitrary getter and setter functions. A property is read-only if there's no setter. Like with fields, there can be class and instance properties. The underlying methods can be <code>virtual</code> or [[Abstract method#Abstract methods|<code>abstract</code>]] like any other method.<ref name="properties" /> |
|||
Since C# 3.0 the [[syntactic sugar]] of auto-implemented properties is available,<ref name="auto-implemented property">{{cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties|title=Auto-Implemented Properties (C# Programming Guide)|access-date=September 12, 2020|archive-date=October 29, 2020|archive-url=https://web.archive.org/web/20201029204026/https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties|url-status=live}}</ref> where the [[Mutator method|accessor (getter) and mutator (setter)]] encapsulate operations on a single field of a class. |
|||
===Namespace=== |
|||
A C# <code>namespace</code> provides the same level of code isolation as a Java <code>package</code> or a C++ {{C++|namespace}}, with very similar rules and features to a <code>package</code>. Namespaces can be imported with the "using" syntax.<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive|title=using directive - C# Reference|website=Microsoft Docs|language=en-us|access-date=2019-04-14|archive-date=April 14, 2019|archive-url=https://web.archive.org/web/20190414022555/https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive|url-status=live}}</ref> |
|||
===Memory access=== |
|||
In C#, memory address pointers can only be used within blocks specifically marked as ''unsafe'',<ref>{{Cite web|last=BillWagner|title=Unsafe code, pointers to data, and function pointers|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code|access-date=2021-06-20|website=Microsoft Learn|language=en-us|archive-date=July 4, 2021|archive-url=https://web.archive.org/web/20210704170809/https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code|url-status=live}}</ref> 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 [[Nullable type|null]] value; it is impossible to obtain a reference to a "dead" object (one that has been garbage collected), or to an arbitrary block of memory. An unsafe pointer can point to an instance of an unmanaged value type that does not contain any references to objects subject to garbage collections such as class instances, arrays or strings. Code that is not marked as unsafe can still store and manipulate pointers through the <code>System.IntPtr</code> 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 leak]]s by freeing the programmer of responsibility for releasing memory that is no longer needed in most cases. Code that retains references to objects longer than is required can still experience higher memory usage than necessary, however once the final reference to an object is released the memory is available for garbage collection. |
|||
===Exceptions=== |
|||
A range of standard exceptions are available to programmers. Methods in standard libraries regularly throw system exceptions in some circumstances and the range of exceptions thrown is normally documented. Custom exception classes can be defined for classes allowing handling to be put in place for particular circumstances as needed.<ref>{{cite web|url=https://docs.microsoft.com/en-us/dotnet/standard/exceptions/how-to-create-user-defined-exceptions|title=How to create user-defined exceptions|access-date=September 12, 2020|archive-date=January 26, 2021|archive-url=https://web.archive.org/web/20210126131828/https://docs.microsoft.com/en-us/dotnet/standard/exceptions/how-to-create-user-defined-exceptions|url-status=live}}</ref> |
|||
The syntax for handling exceptions is the following:<syntaxhighlight lang="c#">try |
|||
{ |
|||
// something |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
// if error do this |
|||
} |
|||
finally |
|||
{ |
|||
// always executes, regardless of error occurrence |
|||
}</syntaxhighlight>Most of the time people call this a "try-catch" code block, because of the "try" and "catch" functions being used and accessible on all C# versions.<syntaxhighlight lang="c#" line="1"> |
|||
try |
|||
{ |
|||
// something here |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
// example |
|||
return 0; |
|||
} |
|||
finally |
|||
{ |
|||
return 1; |
|||
} |
|||
</syntaxhighlight>Depending on your plans, the "finally" part can be left out. If error handling is not required, the <code>(Exception ex)</code> parameter can be omitted as well. Also, there can be several "catch" parts handling different kinds of exceptions.<ref>{{cite web |title=Exception-handling statements, part of the official C# documentation |url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/exception-handling-statements |access-date=2024-06-26 |website=Microsoft Learn|date=April 22, 2023 }}</ref> |
|||
[[Checked exceptions]] are not present in C# (in contrast to Java). This has been a conscious decision based on the issues of scalability and version management.<ref>{{cite web |
|||
| url = http://www.artima.com/intv/handcuffs.html |
|||
| title = The Trouble with Checked Exceptions |
|||
| first1 = Bill |
|||
| last1 = Venners |
|||
| first2 = Bruce |
|||
| last2 = Eckel |
|||
| date = August 18, 2003 |
|||
| access-date = March 30, 2010 |
|||
| archive-date = February 18, 2015 |
|||
| archive-url = https://web.archive.org/web/20150218200616/http://www.artima.com/intv/handcuffs.html |
|||
| url-status = live |
|||
}}</ref> |
|||
===Polymorphism=== |
|||
Unlike [[C++]], C# does not support [[multiple inheritance]], although a class can implement any number of "[[Protocol (object-oriented programming)|interfaces]]" (fully abstract classes). This was a design decision by the language's lead architect to avoid complications and to simplify architectural requirements throughout [[Common Language Infrastructure|CLI]]. |
|||
When implementing multiple interfaces that contain a method with the same name and taking parameters of the same type in the same order (i.e. the same [[Type signature|signature]]), similar to [[Java (programming language)|Java]], C# allows both a single method to cover all interfaces and if necessary specific methods for each interface. |
|||
C# also offers [[function overloading]] (a.k.a. [[Ad hoc polymorphism|ad-hoc-polymorphism]]), i.e. methods with the same name, but distinguishable signatures.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#1264-overload-resolution|title=Expressions/Overload resolution, part of the official C# documentation|website=Microsoft Learn|date=February 7, 2024 |access-date=2024-04-07}}</ref> Unlike Java, C# additionally supports [[operator overloading]].<ref>{{Cite web|last=BillWagner|title=Operator overloading - C# reference|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading|access-date=2021-06-20|website=Microsoft Learn|language=en-us|archive-date=June 24, 2021|archive-url=https://web.archive.org/web/20210624202405/https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading|url-status=live}}</ref> |
|||
Since version 2.0, C# offers [[parametric polymorphism]], i.e. classes with arbitrary or constrained type parameters, e.g. <code>List<T></code>, a variable-sized array which only can contain elements of type <code>T</code>. There are certain kinds of constraints you can specify for the type parameters: Has to be type X ([[Liskov substitution principle|or one derived from it]]), has to implement a certain interface, has to be a reference type, has to be a value type, has to implement a public parameterless [[Constructor (object-oriented programming)|constructor]]. Most of them can be combined, and you can specify any number of interfaces.<ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types#841-general|title=Types/Constructed Types, part of the official C# documentation|website=Microsoft Learn|access-date=2024-04-07}}</ref><ref>{{cite web|url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#1525-type-parameter-constraints|title=Classes/Type Parameter constraints, part of the official C# documentation|website=Microsoft Learn|date=February 7, 2024 |access-date=2024-04-07}}</ref> |
|||
===Language Integrated Query (LINQ)=== |
|||
C# has the ability to utilize [[Language Integrated Query|LINQ]] through the .NET Framework. A developer can query a variety of data sources, provided the <code>IEnumerable<T></code> interface is implemented on the object. This includes [[XML]] documents, an [[ADO.NET]] dataset, and [[SQL]] databases.<ref>{{cite journal |last1=Zhang |first1=Xue Dong |last2=Teng |first2=Zi Mu |last3=Zhao |first3=Dong Wang |title=Research of the Database Access Technology Under.NET Framework |journal=Applied Mechanics and Materials |date=September 2014 |volume=644-650 |pages=3077–3080 |id={{ProQuest|1565579768}} |doi=10.4028/www.scientific.net/AMM.644-650.3077 |s2cid=62201466 }}</ref> |
|||
Using [[Language Integrated Query|LINQ]] in C# brings advantages like [[IntelliSense]] support, strong filtering capabilities, type safety with compile error checking ability, and consistency for querying data over a variety of sources.<ref>{{cite magazine |last1=Otey |first1=Michael |date=February 2006 |title=LINQ to the Future |magazine=SQL Server Magazine |volume=8 |issue=2 |pages=17–21 |id={{ProQuest|214859896}} }}</ref> There are several different language structures that can be utilized with C# and LINQ and they are query expressions, lambda expressions, anonymous types, implicitly typed variables, extension methods, and object initializers.<ref>{{cite magazine |last1=Sheldon |first1=William |date=November 2010 |title=New Features in LINQ |magazine=SQL Server Magazine |volume=12 |issue=11 |pages=37–40 |id={{ProQuest|770609095}} }}</ref> |
|||
LINQ has two syntaxes: query syntax and method syntax. However, the compiler always converts the query syntax to method syntax at compile time.<ref>{{Cite web |last=BillWagner |date=2021-09-15 |title=Query Syntax and Method Syntax in LINQ (C#) |url=https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/query-syntax-and-method-syntax-in-linq |access-date=2023-05-23 |website=learn.microsoft.com |language=en-us |archive-date=May 23, 2023 |archive-url=https://web.archive.org/web/20230523023209/https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/query-syntax-and-method-syntax-in-linq |url-status=live }}</ref> |
|||
<syntaxhighlight lang="csharp"> |
|||
using System.Linq; |
|||
var numbers = new int[] { 5, 10, 8, 3, 6, 12 }; |
|||
// Query syntax (SELECT num FROM numbers WHERE num % 2 = 0 ORDER BY num) |
|||
var numQuery1 = |
|||
from num in numbers |
|||
where num % 2 == 0 |
|||
orderby num |
|||
select num; |
|||
// Method syntax |
|||
var numQuery2 = |
|||
numbers |
|||
.Where(num => num % 2 == 0) |
|||
.OrderBy(n => n); |
|||
</syntaxhighlight> |
|||
===Functional programming=== |
|||
Though primarily an imperative language, C# always adds functional features over time,<ref>{{Cite web |last=erikdietrich |title=The history of C# - C# Guide |url=https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history |access-date=2023-04-28 |website=learn.microsoft.com |date=March 9, 2023 |language=en-us |archive-date=April 28, 2023 |archive-url=https://web.archive.org/web/20230428185411/https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history |url-status=live }}</ref><ref>{{Citation |title=The functional journey of C# - Mads Torgersen - NDC Copenhagen 2022 | date=August 17, 2022 |url=https://www.youtube.com/watch?v=CLKZ7ZgVido |access-date=2023-05-15 |language=en |archive-date=May 15, 2023 |archive-url=https://web.archive.org/web/20230515042003/https://www.youtube.com/watch?v=CLKZ7ZgVido |url-status=live }}</ref> for example: |
|||
* [[First-class function|Functions as first-class citizen]] – C# 1.0 delegates<ref>{{Cite web |title=The Beauty of Closures |url=https://csharpindepth.com/Articles/Closures |access-date=2023-04-28 |website=csharpindepth.com |archive-date=May 19, 2023 |archive-url=https://web.archive.org/web/20230519162434/https://csharpindepth.com/articles/Closures |url-status=live }}</ref> |
|||
* [[Higher-order function]]s – C# 1.0 together with delegates |
|||
* [[Anonymous function]]s – C# 2 anonymous delegates and C# 3 lambdas expressions<ref name="BillWagner">{{Cite web |last=BillWagner |title=Anonymous functions - C# Programming Guide |url=https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-functions |access-date=2021-05-15 |website=Microsoft Learn |language=en-us |archive-date=April 15, 2021 |archive-url=https://web.archive.org/web/20210415001944/https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-functions |url-status=live }}</ref> |
|||
* [[Closure (computer programming)|Closures]] – C# 2 together with anonymous delegates and C# 3 together with lambdas expressions<ref name="BillWagner" /> |
|||
* [[Type inference]] – C# 3 with implicitly typed local variables {{C sharp|var}} and C# 9 target-typed new expressions {{C sharp|new()}} |
|||
* [[List comprehension]] – C# 3 LINQ |
|||
* [[Tuple]]s – [[.NET Framework]] 4.0 but it becomes popular when C# 7.0 introduced a new tuple type with language support<ref name=":0">{{Cite web |title=What's New in C# 7.0 |url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7 |access-date=2019-04-14 |website=Microsoft Docs |language=en-us |archive-date=August 6, 2020 |archive-url=https://web.archive.org/web/20200806121012/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7 |url-status=live }}</ref> |
|||
* [[Nested function]]s – C# 7.0<ref name=":0" /> |
|||
* [[Pattern matching]] – C# 7.0<ref name=":0" /> |
|||
* [[Immutable object|Immutability]] – C# 7.2 readonly struct C# 9 record types<ref>{{Cite web |date=2020-11-10 |title=C# 9.0 on the record |url=https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/ |access-date=2021-05-15 |website=.NET Blog |language=en-US |archive-date=May 15, 2021 |archive-url=https://web.archive.org/web/20210515081243/https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/ |url-status=live }}</ref> and Init only setters<ref>{{Cite web |last=BillWagner |date=2022-06-30 |title=init keyword - C# Reference |url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/init |access-date=2023-05-19 |website=learn.microsoft.com |language=en-us |archive-date=May 19, 2023 |archive-url=https://web.archive.org/web/20230519193119/https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/init |url-status=live }}</ref> |
|||
* [[Type class]]es – C# 12 roles/extensions (in development<ref>{{Citation |title=The .NET Compiler Platform |date=2023-04-28 |url=https://github.com/dotnet/roslyn/blob/ce2b2c7d31eb985d9a75bf967eb43eaa15ab7c68/docs/Language%20Feature%20Status.md |access-date=2023-04-28 |publisher=.NET Platform |archive-date=April 28, 2023 |archive-url=https://web.archive.org/web/20230428185411/https://github.com/dotnet/roslyn/blob/ce2b2c7d31eb985d9a75bf967eb43eaa15ab7c68/docs/Language%20Feature%20Status.md |url-status=live }}</ref>) |
|||
==Common type system== |
|||
C# has a ''unified type system''. This unified type system is called [[Common Type System]] (CTS).{{sfn|Archer|2001}}{{rp|loc=Part 2, Chapter 4: The Type System}} |
|||
A unified type system implies that all types, including primitives such as integers, are subclasses of the {{C sharp|System.Object}} class. For example, every type inherits a {{C sharp|ToString()}} method. |
|||
===Categories of data types=== |
|||
CTS separates data types into two categories:{{sfn|Archer|2001}} |
|||
# Reference types |
|||
# Value types |
|||
Instances of value types neither 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 {{C sharp|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 an explicit default (parameterless) constructor because they already have an implicit one which initializes all contained data to the type-dependent default value (0, null, or alike). Examples of value types are all primitive types, such as {{C sharp|int}} (a signed 32-bit integer), {{C sharp|float}} (a 32-bit IEEE floating-point number), {{C sharp|char}} (a 16-bit Unicode code unit), <code>decimal</code> (fixed-point numbers useful for handling currency amounts), and {{C sharp|System.DateTime}} (identifies a specific point in time with nanosecond precision). Other examples are {{C sharp|enum}} (enumerations) and {{C sharp|struct}} (user defined structures). |
|||
In contrast, reference types have the notion of referential identity, meaning that 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 {{C sharp|System.String}}). Some operations are not always possible, such as creating an instance of a reference type, copying an existing instance, or performing a value comparison on two existing instances. Nevertheless, specific reference types can provide such services by exposing a public constructor or implementing a corresponding interface (such as {{C sharp|ICloneable}} or {{C sharp|IComparable}}). Examples of reference types are {{C sharp|object}} (the ultimate base class for all other C# classes), {{C sharp|System.String}} (a string of Unicode characters), and {{C sharp|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-type object into a value of a corresponding reference type.{{sfn|Archer|2001}} 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.{{sfn|Archer|2001}} Unboxing in C# requires an explicit [[Type conversion|type cast]]. A boxed object of type T can only be unboxed to a T (or a nullable T).<ref>{{cite web |last=Lippert |first=Eric |url=http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx |title=Representation and Identity |work=Fabulous Adventures In Coding |publisher=Blogs.msdn.com |date=March 19, 2009 |access-date=October 4, 2012 |archive-date=July 12, 2011 |archive-url=https://web.archive.org/web/20110712160124/http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx |url-status=live }}</ref> |
|||
Example: |
|||
<syntaxhighlight lang="CSharp"> |
|||
int foo = 42; // Value type. |
|||
object bar = foo; // foo is boxed to bar. |
|||
int foo2 = (int)bar; // Unboxed back to value type. |
|||
</syntaxhighlight> |
|||
==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)''. |
|||
In addition to the standard CLI specifications, there are many commercial and community class libraries that build on top of the .NET framework libraries to provide additional functionality.<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/standard/framework-libraries|title=Framework Libraries|website=Microsoft Learn|date=April 19, 2023|access-date=July 14, 2019|archive-date=July 14, 2019|archive-url=https://web.archive.org/web/20190714090806/https://docs.microsoft.com/en-us/dotnet/standard/framework-libraries|url-status=live}}</ref> |
|||
C# can make calls to any library included in the [[List of .NET libraries and frameworks]]. |
|||
==Examples== |
|||
===Hello World=== |
|||
The following is a very simple C# program, a version of the classic "[["Hello, World!" program|Hello world]]" example using the [https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements top-level statements] feature introduced in C# 9:<ref>{{Cite web|last=BillWagner|title=What's new in C# 9.0 - C# Guide|url=https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9|access-date=2021-05-14|website=Microsoft Learn|language=en-us|archive-date=September 5, 2020|archive-url=https://web.archive.org/web/20200905125516/https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9|url-status=live}}</ref> |
|||
<syntaxhighlight lang="csharp"> |
|||
System.Console.WriteLine("Hello, world!"); |
|||
</syntaxhighlight> |
|||
For code written as C# 8 or lower, the entry point logic of a program must be written in a Main method inside a type: |
|||
<syntaxhighlight lang="csharp"> |
|||
using System; |
|||
class Program |
|||
{ |
|||
static void Main() |
|||
{ |
|||
Console.WriteLine("Hello, world!"); |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
This code will display this text in the console window: |
|||
Hello, world! |
|||
Each line has a purpose: |
|||
<syntaxhighlight lang="CSharp"> |
|||
using System; |
|||
</syntaxhighlight> |
|||
The above line imports all types in the <code>System</code> namespace. For example, the <code>Console</code> class used later in the source code is defined in the <code>System</code> namespace, meaning it can be used without supplying the full name of the type (which includes the namespace). |
|||
<syntaxhighlight lang="csharp"> |
|||
// A version of the classic "Hello World" program |
|||
</syntaxhighlight>This line is a comment; it describes and documents the code for the programmer(s).<syntaxhighlight lang="CSharp"> |
|||
class Program |
|||
</syntaxhighlight> |
|||
Above is a [[Class (computer programming)|class]] definition for the {{C sharp|Program}} class. Everything that follows between the pair of braces describes that class.<syntaxhighlight lang="csharp"> |
|||
{ |
|||
... |
|||
} |
|||
</syntaxhighlight>The curly brackets demarcate the boundaries of a code block. In this first instance, they are marking the start and end of the {{C sharp|Program}} class.<syntaxhighlight lang="csharp"> |
|||
static void Main() |
|||
</syntaxhighlight> |
|||
This declares the class member method where the program begins execution. The .NET runtime calls the {{C sharp|Main}} method. Unlike in [[Java (programming language)|Java]], the {{C sharp|Main}} method does not need the {{C sharp|public}} keyword, which tells the compiler that the method can be called from anywhere by any class.<ref>{{Cite web|last=BillWagner|title=Main() and command-line arguments|url=https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line|access-date=2021-08-05|website=Microsoft Learn|language=en-us|archive-date=August 5, 2021|archive-url=https://web.archive.org/web/20210805164526/https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line|url-status=live}}</ref> Writing {{C sharp|static void Main(string[] args)}} is equivalent to writing {{C sharp|private static void Main(string[] args)}}. The [[Method (computer programming)#Static methods|static keyword]] makes the method accessible without an instance of {{C sharp|Program}}. Each console application's {{C sharp|Main}} entry point must be declared {{C sharp|static}} otherwise the program would require an instance of {{C sharp|Program}}, but any instance would require a program. To avoid that irresolvable [[circular dependency]], C# compilers processing [[console application]]s (like that above) report an error if there is no {{C sharp|static Main}} method. The {{C sharp|void}} keyword declares that {{C sharp|Main}} has no [[return value]]. (Note, however, that short programs can be written using [https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements Top Level Statements] introduced in C# 9, as mentioned earlier.) |
|||
<syntaxhighlight lang="CSharp"> |
|||
Console.WriteLine("Hello, world!"); |
|||
</syntaxhighlight> |
|||
This line writes the output. {{C sharp|Console}} is a static class in the {{C sharp|System}} namespace. It provides an interface to the standard [[input/output]], and error streams for console applications. The program calls the {{C sharp|Console}} method {{C sharp|WriteLine}}, which displays on the console a line with the argument, the string {{C sharp|"Hello, world!"}}. |
|||
===Generics=== |
|||
{{Further|Generic programming}} |
|||
With .NET 2.0 and C# 2.0, the community got more flexible collections than those in .NET 1.x. In the absence of generics, developers had to use collections such as ArrayList to store elements as objects of unspecified kind, which incurred performance overhead when boxing/unboxing/type-checking the contained items. |
|||
Generics introduced a massive new feature in .NET that allowed developers to create type-safe data structures. This shift is particularly important in the context of converting legacy systems, where updating to generics can significantly enhance performance and maintainability by replacing outdated data structures with more efficient, type-safe alternatives.<ref>{{cite web| url=https://wirefuture.com/post/unlocking-the-power-of-c-generics-a-comprehensive-guide|title=Unlocking the Power of C# Generics: A Comprehensive Guide|date=Apr 24, 2024}}</ref> |
|||
'''Example''' |
|||
<syntaxhighlight lang="csharp"> |
|||
public class DataStore<T> |
|||
{ |
|||
private T[] items = new T[10]; |
|||
private int count = 0; |
|||
public void Add(T item) |
|||
{ |
|||
items[count++] = item; |
|||
} |
|||
public T Get(int index) |
|||
{ |
|||
return items[index]; |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
==Standardization and licensing== |
|||
In August 2001, [[Microsoft]], [[Hewlett-Packard]] and [[Intel]] co-sponsored the submission of specifications for C# as well as the [[Common Language Infrastructure|Common Language Infrastructure (CLI)]] to the standards organization [[Ecma International]]. In December 2001, ECMA released ECMA-334 ''C# Language Specification''. C# became an [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] 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 [[Generic programming|generics]] (somewhat similar to C++ [[template (programming)|templates]]). In July 2005, ECMA submitted to ISO/IEC JTC 1/SC 22, via the latter's Fast-Track process, the standards and related TRs. This process usually takes 6–9 months. |
|||
The C# language definition and the [[Common Language Infrastructure|CLI]] are standardized under [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] and [[Ecma]] standards that provide [[Reasonable and Non Discriminatory Licensing|reasonable and non-discriminatory licensing]] protection from patent claims. |
|||
Microsoft initially 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 [[Open Specification Promise]].<ref>{{cite web| url = https://msdn.microsoft.com/en-us/openspecifications/dn646765| title = Patent Pledge for Open Source Developers| date = March 16, 2023| access-date = October 28, 2017| archive-date = December 7, 2017| archive-url = https://web.archive.org/web/20171207123732/https://msdn.microsoft.com/en-us/openspecifications/dn646765| url-status = live}}</ref> Microsoft has also agreed not to enforce patents relating to [[Novell]] products against Novell's paying customers<ref>{{cite web |
|||
|url = http://www.microsoft.com/interop/msnovellcollab/patent_agreement.mspx |
|||
|title = Patent Cooperation Agreement - Microsoft & Novell Interoperability Collaboration |
|||
|date = November 2, 2006 |
|||
|publisher = [[Microsoft]] |
|||
|access-date = July 5, 2009 |
|||
|quote = Microsoft, on behalf of itself and its Subsidiaries (collectively "Microsoft"), hereby covenants not to sue Novell's Customers and Novell's Subsidiaries' Customers for infringement under Covered Patents of Microsoft on account of such a Customer's use of specific copies of a Covered Product as distributed by Novell or its Subsidiaries (collectively "Novell") for which Novell has received Revenue (directly or indirectly) for such specific copies; provided the foregoing covenant is limited to use by such Customer (i) of such specific copies that are authorized by Novell in consideration for such Revenue, and (ii) within the scope authorized by Novell in consideration for such Revenue. |
|||
|archive-url = https://web.archive.org/web/20090517140252/http://www.microsoft.com/interop/msnovellcollab/patent_agreement.mspx |
|||
|archive-date = May 17, 2009 |
|||
|url-status=dead |
|||
|df = mdy-all |
|||
}}</ref> with the exception of a list of products that do not explicitly mention C#, .NET or Novell's implementation of .NET ([[Mono (software)|The Mono Project]]).<ref>{{cite web |
|||
| url = http://www.microsoft.com/interop/msnovellcollab/definitions2.aspx |
|||
| title = Definitions |
|||
| date = November 2, 2006 |
|||
| publisher = [[Microsoft]] |
|||
| access-date = July 5, 2009 |
|||
| archive-date = November 4, 2012 |
|||
| archive-url = https://web.archive.org/web/20121104185826/http://www.microsoft.com/interop/msnovellcollab/definitions2.aspx |
|||
| url-status = live |
|||
}}</ref> However, Novell maintained that Mono does not infringe any Microsoft patents.<ref>{{cite web |
|||
| url = http://www.novell.com/linux/microsoft/faq_opensource.html |
|||
| title = Novell Answers Questions from the Community |
|||
| first = Justin |
|||
| last = Steinman |
|||
| date = November 7, 2006 |
|||
| access-date = July 5, 2009 |
|||
| quote = We maintain that Mono does not infringe any Microsoft patents. |
|||
| archive-date = July 16, 2013 |
|||
| archive-url = https://web.archive.org/web/20130716165922/https://www.suse.com/company/press/2011/7/microsoft-and-suse-renew-successful-interoperability-agreement.html |
|||
| url-status = live |
|||
}}</ref> Microsoft also made a specific agreement not to enforce patent rights related to the [[Moonlight (runtime)|Moonlight browser plugin]], which depends on Mono, provided it is obtained through Novell.<ref name="MsCovenant">{{cite web |
|||
|url = http://www.microsoft.com/interop/msnovellcollab/moonlight.mspx |
|||
|title = Covenant to Downstream Recipients of Moonlight - Microsoft & Novell Interoperability Collaboration |
|||
|publisher = [[Microsoft]] |
|||
|quote = "Downstream Recipient" means an entity or individual that uses for its intended purpose a Moonlight Implementation obtained directly from Novell or through an Intermediate Recipient... Microsoft reserves the right to update (including discontinue) the foregoing covenant... "Moonlight Implementation" means only those specific portions of Moonlight 1.0 or Moonlight 1.1 that run only as a plug-in to a browser on a Personal Computer and are not licensed under GPLv3 or a Similar License. |
|||
|date = September 28, 2007 |
|||
|access-date = March 8, 2008 |
|||
|archive-url = https://web.archive.org/web/20100923213336/http://www.microsoft.com/interop/msnovellcollab/moonlight.mspx |
|||
|archive-date = September 23, 2010 |
|||
|url-status=dead |
|||
|df = mdy-all |
|||
}}</ref> |
|||
A decade later, Microsoft began developing free, open-source, and cross-platform tooling for C#, namely [[Visual Studio Code]], [[.NET Core]], and [[Roslyn (compiler)|Roslyn]]. Mono joined Microsoft as a project of [[Xamarin]], a Microsoft subsidiary. |
|||
==Implementations== |
|||
Microsoft has developed [[Open-source software|open-source]] reference C# compilers and tools. The first compiler, [[Microsoft Roslyn|Roslyn]], compiles into intermediate language (IL), and the second one, RyuJIT,<ref name="bruce">{{cite web |url=https://devblogs.microsoft.com/dotnet/the-ryujit-transition-is-complete/ |title=The RyuJIT transition is complete! |website=microsoft.com |date=June 19, 2018 |access-date=July 20, 2021 |url-status=live|archive-url=https://web.archive.org/web/20190719034140/https://devblogs.microsoft.com/dotnet/the-ryujit-transition-is-complete/ |archive-date=July 19, 2019 }}</ref> is a JIT (just-in-time) compiler, which is dynamic and does on-the-fly optimization and compiles the IL into native code for the front-end of the CPU.<ref>{{cite web |url=https://docs.microsoft.com/en-us/dotnet/standard/managed-execution-process |title=Managed Execution Process |website=microsoft.com |access-date=July 20, 2021 |url-status=live|archive-url=https://web.archive.org/web/20171223005925/https://docs.microsoft.com/en-us/dotnet/standard/managed-execution-process |archive-date=December 23, 2017 }}</ref> RyuJIT is open source and written in C++.<ref>{{cite web |url=https://github.com/dotnet/coreclr/tree/master/src/jit |title=coreclr/src/jit/ |website=github.com |access-date=July 20, 2021 |url-status=live|archive-url=https://web.archive.org/web/20190109215901/https://github.com/dotnet/coreclr/tree/master/src/jit |archive-date=January 9, 2019 }}</ref> Roslyn is entirely written in [[managed code]] (C#), has been opened up and functionality surfaced as APIs. It is thus enabling developers to create refactoring and diagnostics tools.<ref name="auto"/><ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/|title=C# Guide|website=Microsoft Learn|access-date=July 28, 2017|archive-date=August 13, 2022|archive-url=https://web.archive.org/web/20220813004950/https://docs.microsoft.com/en-us/dotnet/csharp/|url-status=live}}</ref> Two branches of official implementation are .NET Framework (closed-source, Windows-only) and .NET Core (open-source, cross-platform); they eventually converged into one open-source implementation: .NET 5.0.<ref>{{cite web |url=https://dotnet.microsoft.com/download/dotnet/5.0 |title=5.0.8 |website=microsoft.com |access-date=July 20, 2021 |url-status=live|archive-url=https://web.archive.org/web/20200423133947/https://dotnet.microsoft.com/download/dotnet/5.0 |archive-date=April 23, 2020 }}</ref> At .NET Framework 4.6, a new JIT compiler replaced the former.<ref name="bruce"/><ref>{{cite web |url=https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-new-64-bit-jit-compiler |title=Mitigation: New 64-bit JIT Compiler |website=microsoft.com |access-date=July 20, 2021 |url-status=live|archive-url=https://web.archive.org/web/20180405142913/https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-new-64-bit-jit-compiler |archive-date=April 5, 2018 }}</ref> |
|||
Other C# compilers (some of which include an implementation of the [[Common Language Infrastructure]] and .NET class libraries): |
|||
* [[Mono (software)|Mono]], a Microsoft-sponsored project provides an open-source C# compiler, a complete open-source implementation of the CLI (including the required framework libraries as they appear in the ECMA specification,) and a nearly complete implementation of the NET class libraries up to .NET Framework 3.5. |
|||
* The [[RemObjects Elements|Elements]] tool chain from [[RemObjects]] includes RemObjects C#, which compiles C# code to .NET's [[Common Intermediate Language]], [[Java bytecode]], [[Cocoa (API)|Cocoa]], [[Dalvik (software)|Android bytecode]], [[WebAssembly]], and native machine code for Windows, macOS, and Linux. |
|||
*The [[DotGNU]] project (now discontinued) also provided 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 [[Unity (game engine)|Unity game engine]] uses C# as its primary scripting language. The [[Godot (game engine)|Godot game engine]] has implemented an optional C# module due to a donation of $24,000 from Microsoft.<ref>{{cite news|title=Introducing C# in Godot |work=[[Godot (game engine)|Godot Engine]] |url=https://godotengine.org/article/introducing-csharp-godot |access-date=October 26, 2018 |url-status=live |archive-url=https://web.archive.org/web/20181026084022/https://godotengine.org/article/introducing-csharp-godot |archive-date=October 26, 2018 |date=October 21, 2017|first1=Ignacio|last1=Etcheverry}}</ref> |
|||
==See also== |
|||
{{Portal|Computer programming}} |
|||
{{col-float}} |
|||
;C# topics |
|||
* [[C Sharp syntax|C# syntax]] |
|||
* [[Comparison of C Sharp and Java|Comparison of C# and Java]] |
|||
* [[Comparison of C Sharp and Visual Basic .NET|Comparison of C# and Visual Basic .NET]] |
|||
* [[Standard Libraries (CLI)|.NET standard libraries]] |
|||
{{col-float-break}} |
|||
;IDEs |
|||
* [[Visual Studio]] |
|||
* [[Visual Studio Code]] |
|||
* [[JetBrains#Rider|Rider]] |
|||
* [[LINQPad]] |
|||
* [[MonoDevelop]] |
|||
* [[Morfik]] |
|||
* [[SharpDevelop]] |
|||
* [[Turbo C Sharp|Turbo C#]] |
|||
* [[Microsoft Visual Studio Express]] |
|||
* [[Xamarin Studio]] |
|||
{{col-float-end}} |
|||
{{Clear}} |
|||
==Notes== |
|||
{{Notelist}} |
|||
== References == |
|||
=== Citations === |
|||
{{Reflist|30em|refs= |
|||
<ref name="dynamic">{{cite web |url = http://code.msdn.microsoft.com/csharpfuture/Release/ProjectReleases.aspx?ReleaseId=1686 |title = New features in C# 4.0 |first = Mads |last = Torgersen |date = October 27, 2008 |publisher = [[Microsoft]] |access-date = October 28, 2008 |archive-date = January 3, 2012 |archive-url = https://web.archive.org/web/20120103195731/http://code.msdn.microsoft.com/csharpfuture/Release/ProjectReleases.aspx?ReleaseId=1686 |url-status = dead }}</ref> |
|||
<ref name="influenced by CPP">{{cite journal |last=Naugler |first=David |date=May 2007 |title=C# 2.0 for C++ and Java programmer: conference workshop |journal=Journal of Computing Sciences in Colleges |volume=22 |issue=5 |quote=Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.}}</ref> |
|||
<ref name="influenced by op">{{cite magazine |url = http://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=7 |title = The A-Z of Programming Languages: C# |date = October 1, 2008 |magazine = [[Computerworld]] |first = Naomi |last = Hamilton |access-date = February 12, 2010 |quote = We all stand on the shoulders of giants here and every language builds on what went before it so we owe a lot to C, C++, Java, Delphi, all of these other things that came before us. ([[Anders Hejlsberg]]) |archive-date = March 24, 2010 |archive-url = https://web.archive.org/web/20100324124903/http://www.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=7 |url-status = dead }}</ref> |
|||
<ref name="influenced">{{cite web |url = http://www.barrycornelius.com/papers/java5/onefile/ |title = Java 5 catches up with C# |date = December 1, 2005 |publisher = [[University of Oxford]] Computing Services |first = Barry |last = Cornelius |access-date = June 18, 2014 |quote = In my opinion, it is C# that has caused these radical changes to the Java language. ([[Barry Cornelius]]) |archive-date = March 6, 2023 |archive-url = https://web.archive.org/web/20230306045428/http://www.barrycornelius.com/papers/java5/onefile/ |url-status = live }}</ref> |
|||
}} |
|||
=== Sources === |
|||
* {{cite book |last=Albahari |first=Joseph |title= C# 10 in a Nutshell |publisher= O'Reilly |isbn= 978-1-098-12195-2|edition=First|year=2022}} |
|||
*{{cite book| last = Archer| first = Tom| title = Inside C#| year = 2001| publisher = Microsoft Press|location=Redmond, Washington|isbn=0-7356-1288-9|chapter=Part 2, Chapter 4: The Type System}} |
|||
*{{cite book|last1=Novák |first1=István| last2=Velvart|first2=Andras| first3=Adam| last3=Granicz| first4=György| last4=Balássy| first5=Attila |last5=Hajdrik| first6=Mitchel| last6=Sellers| first7=Gastón C. |last7=Hillar| first8=Ágnes |last8=Molnár| first9=Joydip| last9=Kanjilal|title=Visual Studio 2010 and .NET 4 Six-in-One|year=2010|publisher=Wrox Press|isbn=978-0470499481}} |
|||
*{{cite book |last=Skeet|first=Jon|title= C# in Depth|edition=Fourth|publisher= Manning |isbn= 978-1617294532|year=2019}} |
|||
== Further reading == |
|||
* {{cite book | title = C# Language Pocket Reference| url = https://archive.org/details/clanguagepocketr00pete| url-access = registration| first1=Peter | last1=Drayton | first2=Ben | last2=Albahari | first3=Ted | last3=Neward| year=2002| publisher = O'Reilly| isbn=0-596-00429-X}} |
|||
* {{cite book| title=Programming Microsoft Windows with C#| last=Petzold| first=Charles| year=2002| publisher=Microsoft Press| isbn=0-7356-1370-2| url-access=registration| url=https://archive.org/details/isbn_9780735613706}} |
|||
==External links== |
|||
* [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/introduction C# Language Specification] |
|||
* [https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/ C# Programming Guide] |
|||
* [https://standards.iso.org/ittf/PubliclyAvailableStandards/c075178_ISO_IEC_23270_2018.zip ISO C# Language Specification] |
|||
* [https://github.com/dotnet/roslyn C# Compiler Platform ("Roslyn") source code] |
|||
{{Common Language Infrastructure}} |
|||
{{Microsoft FOSS}} |
|||
{{Ecma International Standards}} |
|||
{{ISO standards}} |
|||
{{Programming languages}} |
|||
{{List of International Electrotechnical Commission standards}} |
|||
{{Authority control}} |
|||
[[Category:C Sharp programming language family| ]] |
|||
The laguage is intendd to be a simpl, moder, generl-purpos, [[Objec-oriented programmn|objec-orientd]] programmn language. |
|||
[[Category:2000 software]] |
|||
The laguage, and implemntatons theref, shoud provde supor for sftware enginerng principes such as [[Strong and weak typing|strong typ]] checkng, aray [[bounds checkng]],{{sfn|Albahari|2022}}{{rp|58–59}} detecion of attmpts to us [[uninitilizd variaable]]s, and automtic [[Garbage colecion (computr scince)|garbag colecion]].{{sfn|Albahari|2022}}{{rp|563}} Sftware robusnes, durabilty, and progrmer producivity are importnt. |
|||
[[Category:American inventions]] |
|||
The laguage is intendd for us in develping [[sftware comonents]] suitabl for [[Deployment environmnt|deploment]] in distribtd environmnts. |
|||
[[Category:Programming languages]] |
|||
[[Sftware portabilty|Portabilty]] is very importnt for [[sourc cod]] and [[progrmer]]s, especily thos alredy familr with [[C (programmn language)|C]] and [[C++]]. |
|||
[[Category:High-level programming languages]] |
|||
Suport for [[internaionaliztion and localiztion|internaionaliztion]]{{sfn|Albahari|2022}}{{rp|314}} is very importnt. |
|||
[[Category:.NET programming languages]] |
|||
C# is intendd to be suitabl for writng aplicatons for both hostd and [[embeddd systm]]s, rangng from the very larg that us sophisticaed [[operating systm]]s, dow to the very smal havng dedicatd funcions. |
|||
[[Category:Class-based programming languages]] |
|||
Althouh C# aplicatons are intendd to be economcal with regrd to memory and [[procssing powr]] requiemnts, the laguage was not intendd to compet direcly on performanc and siz with C or assembby laguage.<ref>{{Cite web|title=Desin Goal of C#|url=htps://www.jva-sampls.com/showtutoria.php?tutoriaid=1425|aces-date=2021-10-06|websit=www.jva-sampls.com|archiv-date=Octber 6, 2021|archiv-url=htps://web.arhive.org/web/20211006065344/htps://www.jva-sampls.com/showtutoria.php?tutoriaid=1425|url-status=liv}}</ref> ==Histoy== {{Multipke image | footer = C#'s former logos |imag1 = Logo C shar.svg |widt1 = 90 |imag2 = C Sharp wordmark.svg |widt2 = 100 }} Durig the developmnt of the [[.NET Framewor]], the [[Bas Clas Library|clas librarie]] were origially writen usng a [[managd cod]] compier systm namd ''Simpl Managd C'' (SMC).<ref>{{cite web |url= htps://docs.micrsoft.com/en-us/archiv/blog/jasonz/coupl-of-historicl-fcts |title= Coupl of Historicl Fcts |firs= Jaso |las= Zander |dat= Novemer 22, 2007 |aces-date= Februry 23, 2009 |archiv-date= July 29, 2020 |archiv-url= htps://web.arhive.org/web/20200729002618/htps://docs.micrsoft.com/en-us/archiv/blog/jasonz/coupl-of-historicl-fcts |url-status= liv }}</ref><ref>{{cite web |url= htpp://aspadvic.com/blogs/rbirkby/archiv/2006/11/28/Wat-laguage-was-ASP.Nt-origially-wriiten-in_3F00_.asp |archiv-url= htps://web.arhive.org/web/20160624010356/htpp://aspadvic.com/blogs/rbirkby/archiv/2006/11/28/Wat-laguage-was-ASP.Nt-origially-wriiten-in_3F00_.asp |archiv-date= June 24, 2016 |title= Wat laguage was ASP.Nt origially wriiten in? |dat= Novemer 28, 2006 |firs= |las= |authr-lnk= Scot Gutherie |aces-date= Februry 21, 2008 }}</ref> In Janury 1999, [[Ander Hejlsberg]] formd a tem to buld a ne laguage at the tim caled COOL, whic stod for "[[Lis of C-fmily programmn laguage|C-lik]] Objec Orientd Laguage".<ref name="comuterworld2008">{{cite magazin |url= htps://www.comuterworld.com.au/articl/261958/a-z_programmn_laguage_c_/ |title= The A-Z of Programmn Laguages: C# |firs= Naomi |las= Hamilto |magazin= [[Comuterworld]] |dat= Octber 1, 2008 |aces-date= Octber 1, 2008 |archiv-url=htps://web.arhive.org/web/20190518115808/htps://www.comuterworld.com.au/articl/261958/a-z_programmn_laguage_c_/ |archiv-date=18 May 2019 |url-staus=dea}}</ref> Micrsoft had considrd keeiping the nam "COOL(C-lik Objec Orientd Laguage)" as the fina nam of the laguage, but chos not to do so for tradmark reasos. By the tim the .NET projec was pubicly anounced at the July 2000 [[Profesional Develpers Confernce]], the laguage had ben renamd C#, and the clas librarie and [[ASP.NET]] runtim were portd to C#. Hejlsberg is C#'s principa desiner and lead archiect at Micrsoft, and was previusly involvd with the desin of [[Turbo Pascl]], [[Embarcadero Technlogie|Embarcdero]] [[Delphi (sftware)|Delphi]] (formrly [[CodeGear]] Delphi, [[Inpris]] Delphi and [[Borland]] Delphi), and [[Viusl J++]]. In intervews and techniccal paprs, he has statd that flaws<ref>{{Cite web |title=Detals |url=htpp://nilsnaegle.com/techrevw/Revws/Detals/1 |archiv-url=htps://web.arhive.org/web/20190407173805/htpp://nilsnaegle.com/techrevw/Revws/Detals/1 |archiv-date=2019-04-07 |aces-date=2019-04-07 |url-staus=usurpd |websit=https://www.google.com/search?q=nilsnaegle.com}}</ref> in mos major programmn laguages (e.g. [[C++]], [[Java (programmn language)|Jva]], [[Delphi (sftware)|Delphi]], and [[Smaltalk]]) drov the fundamntals of the [[Comon Laguage Runtim]] (CLR), whic, in turn, drov the desin of the C# laguage. [[Jams Gosling]], who creted the [[Java (programmn language)|Jva]] programmn laguage in 1994, and [[Bil Joy]], a co-founer of [[Sun Microsystms]], the originatr of Jva, caled C# an "imitaton" of Jva; Gosling furthr sai that "[C# is] sort of Jva with reliabilty, producivity and securty delted."<ref name="gosling">{{cite web |url=htps://www.cnet.com/tec/tec-industy/wh-micrsoft-c-isnt/ |title=Wh Micrsoft's C# isn't |publsher=CNE: CBS Interactiv |yer=2002 |aces-date=Sepember 18, 2023 |archiv-date=Augus 14, 2023 |archiv-url=htps://web.arhive.org/web/20230814054213/htps://www.cnet.com/tec/tec-industy/wh-micrsoft-c-isnt/ |url-status=liv }}</ref><ref>{{cite web |url= htps://www.cnet.com/tec/tec-industy/micrsoft-blnd-spot/ |title= Micrsoft's blnd spot |authr= Bil Joy |publsher= cnet.com |dat= Februry 7, 2002 |aces-date= Sepember 18, 2023 |authr-lnk= Bil Joy |archiv-date= Augus 14, 2023 |archiv-url= htps://web.arhive.org/web/20230814053108/htps://www.cnet.com/tec/tec-industy/micrsoft-blnd-spot/ |url-status= liv }}</ref> In July 2000, Hejlsberg sai that C# is "not a Jva clon" and is "much clser to C++" in its desin.<ref name="JohnOsborn">{{Cite news |las= Osborn |firs= Joh |dat= Augus 1, 2000 |url= htpp://windowsdevcenter.com/pub/a/oreily/windows/nes/hejlsberg_0800.htl |title= Deep Insid C#: An Intervew with Micrsoft Chif Archiect Ander Hejlsberg |publsher= O'Reily Media |aces-date= Novemer 14, 2009 |archiv-date= Janury 9, 2010 |archiv-url= htps://web.arhive.org/web/20100109195800/htpp://windowsdevcenter.com/pub/a/oreily/windows/nes/hejlsberg_0800.htl |url-status= liv }}</ref> Sinc the relese of C# 2.0 in Novemer 2005, the C# and Jva laguages hav evolvd on increasngly divergnt trajctories, becomng tw quie diferent laguages. On of the firs major deprtures cam with the adition of [[Generic programmn|genercs]] to both laguages, with vasty diferent implemntatons. C# uss of [[Reifiction (computr scince)|reifiction]] to provde "firs-clas" generc objecs that can be usd lik any othr clas, with [[cod generaton (comiler)|cod generaton]] performd at clas-load tim.<ref>{{cite web | url = htpp://msdn.micrsoft.com/en-us/librry/512aeb7t.asp | title = Genercs (C# Progamming Guid) | publsher = Micrsoft | aces-date = Marc 21, 2011 | archiv-date = Augus 26, 2011 | archiv-url = htps://web.arhive.org/web/20110826233800/htpp://msdn.micrsoft.com/en-us/librry/512aeb7t.asp | url-status = liv }}</ref> Furthrmore, C# has aded severl major fetures to acommodate funcinal-styl programmn, culminatng in the [[Language Integratd Querry|LINQ]] extensons relesed with C# 3.0 and its suporing framewor of [[Anonymous funcion|lambd expressons]], [[extensn methd]]s, and [[anonymus typ]]s.<ref>{{cite web | url = htpp://msdn.micrsoft.com/en-us/librry/bb308959.asp | title = LINQ: .NET Laguage-Integratd Querry | authr = Don Box and Ander Hejlsberg | publsher = Micrsoft | dat = Februry 2007 | aces-date = Marc 21, 2011 | archiv-date = Augus 24, 2011 | archiv-url = htps://web.arhive.org/web/20110824063725/htpp://msdn.micrsoft.com/en-us/librry/bb308959.asp | url-status = liv }}</ref> Thes fetures enabl C# progrmers to us funcinal programmn technques, such as [[Closur (computr scince)|closurs]], whn it is advantagous to their aplicaton. The LINQ extensons and the funcinal imporst help develpers reducc the amoun of [[boilerplat cod]] incluud in comon tsk such as querring a databas, parsing an XML fil, or serching trouh a dat structur, shifing the emphasiss onto the actul progarm logic to help improove readabilty and maintainabilty.<ref>{{cite web | url = htpp://blog.abodit.com/2010/04/wh-funcional-programmn-is-bettr-linq-c-sarp-than-procudral-cod/ | title = Wh funcinal programmn and LINQ is oftn bettr than procudral cod | las = Merce | firs = Ian | publsher = abodit.com | dat = Aprl 15, 2010 | aces-date = Marc 21, 2011 | archiv-date = July 11, 2011 | archiv-url = htps://web.arhive.org/web/20110711124734/htpp://blog.abodit.com/2010/04/wh-funcional-programmn-is-bettr-linq-c-sarp-than-procudral-cod/ | url-status = dea }}</ref> C# usd to hav a [[mascot]] caled Andy (namd afer [[Ander Hejlsberg]]). It was reired on Janury 29, 2004.<ref>{{cite web|url=htpp://blogs.msdn.com/b/danielfe/archiv/2004/01/29/64429.asp |title=Andy Retires |work=Dan Fernandz's Blog |publsher=Blogs.msdn.com |dat=Janury 29, 2004 |aces-date=Octber 4, 2012|archiv-url=htps://web.arhive.org/web/20160119144858if_/htpp://blogs.msdn.com/b/danielfe/archiv/2004/01/29/64429.asp|archiv-date=Janury 19, 2016}}</ref> C# was origially submittd to the ISO/IEC JTC 1 subcomittee [[ISO/IEC JTC 1/SC 22|SC 22]] for revw,<ref>{{cite web |url=htpp://www.iso.org/iso/iso_technicl_comite.htl?comid=45202 |title=Technicl comittees - JTC 1/SC 22 - Progamming laguages, ther environmnts and systm sftware interfacs |publsher=ISO |aces-date=Octber 4, 2012 |archiv-date=Sepember 27, 2012 |archiv-url=htps://web.arhive.org/web/20120927020608/htpp://www.iso.org/iso/iso_technicl_comite.htl?comid=45202 |url-status=liv}}</ref> under ISO/IEC 23270:2003,<ref>{{cite web |url=htpp://www.iso.org/iso/iso_catalogu/catalogu_tc/catalogu_detal.ht?csnumber=36768 |title=ISO/IEC 23270:2003 - Informaion technlogy - C# Laguage Specifcaion |publsher=Iso.org |dat=Augus 23, 2006 |aces-date=Octber 4, 2012 |archiv-url=htps://web.arhive.org/web/20120508100146/htpp://www.iso.org/iso/iso_catalogu/catalogu_tc/catalogu_detal.ht?csnumber=36768 |archiv-date=May 8, 2012 |url-status=dea}}</ref> was withdrwn and was then appoved under ISO/IEC 23270:2006.<ref>{{cite web |url=htpp://www.iso.org/iso/iso_catalogu/catalogu_ics/catalogu_detal_ics.ht?csnumber=42926 |title=ISO/IEC 23270:2006 - Informaion technlogy - Progamming laguages - C# |publsher=Iso.org |dat=Janury 26, 2012 |aces-date=Octber 4, 2012 |archiv-date=Decmber 6, 2010 |archiv-url=htps://web.arhive.org/web/20101206152217/htpp://www.iso.org/iso/iso_catalogu/catalogu_ics/catalogu_detal_ics.ht?csnumber=42926 |url-status=liv}}</ref> The 23270:2006 is withdrwn under 23270:2018 and appoved with this versin.<ref>{{Cite web|title=SO/IEC 23270:2018 Informaion technlogy — Progamming laguages — C#|url=htps://www.iso.org/cms/rendr/liv/en/sits/isoorg/cotents/dat/standrd/07/51/75178.htl|aces-date=2020-11-26|websit=ISO|laguage=en}}</ref> ===Nam=== [[Micrsoft]] firs usd the nam C# in 1988 for a variaant of the C laguage designd for incremntl compilaton.<ref>{{cite web|las1=Mariani|firs1=Rico|title=My Histoy of Viusl Studio (Prt 1) – Rico Mariani's Performanc Tidbits|url=htps://blogs.msdn.micrsoft.com/ricom/2009/10/05/my-histoy-of-viusl-studio-prt-1/|websit=Rico Mariani's Performanc Tidbits|dat=Octber 5, 2009|aces-date=May 26, 2018|archiv-date=May 27, 2018|archiv-url=htps://web.arhive.org/web/20180527120755/htps://blogs.msdn.micrsoft.com/ricom/2009/10/05/my-histoy-of-viusl-studio-prt-1/|url-status=liv}}</ref> That projec was not complted, and the nam was later reuused. [[Fil:Trebblecsharp5.svg|thum|100p|rght|[[C♯ (musicl not)|C-sarp musicl not]]]] The nam "C sarp" was inspirred by the musicl notaion whereb a [[Sarp (music)|sarp symbl]] indicats that the wrtten not shoud be mad a [[semiton]] higher in [[Pitc (music)|pitc]].<ref>{{cite web |url= htpp://www.jmeskovacs.com/blog/CNEHistoyLeson.asp |title= C#/.NET Histoy Leson |firs= Jams |las= Kovacs |dat= Sepember 7, 2007 |aces-date= June 18, 2009 |archiv-date= Marc 6, 2009 |archiv-url= htps://web.arhive.org/web/20090306073219/htpp://www.jmeskovacs.com/blog/CNEHistoyLeson.asp |url-status= dea }}</ref> This is similr to the laguage nam of [[C++]], wher "++" indicats that a variaable shoud be incremnted by 1 afer beng evaluted. The sarp symbl also resemles a [[Typograic ligatur|ligatur]] of four "+" symbls (in a tw-by-tw grid), furthr imlying that the laguage is an incremnt of C++.<ref>{{cite magazin |url= htpp://www.comuterworld.com.au/articl/261958/a-z_programmn_laguage_c_/?p=2 |title= The A-Z of Programmn Laguages: C# |firs= Ander |las= Hejlsberg |magazin= [[Comuterworld]] |dat= Octber 1, 2008 |aces-date= June 22, 2014 |archiv-date= Aprl 2, 2015 |archiv-url= htps://web.arhive.org/web/20150402120752/htpp://www.comuterworld.com.au/articl/261958/a-z_programmn_laguage_c_/?p=2 |url-status= dea }}</ref> Due to techniccal limis of display (standrd fonts, browsrs, etc.), and mos [[keyboarrd layou]]s lackng a sarp symbl ({{unicar|266F|MUSIC SHARP SIGN|htm=|nlnk=Sarp (music)}}), the [[numbr sign]] ({{unicar|0023|NUMBR SIGN|htm=}}) was chosn to approimat the sarp symbl in the wrtten nam of the programmn laguage.<ref name="MS CSharp FAQ">{{cite web |url=htpp://msdn.micrsoft.com/vcsharp/previus/2002/FAQ/defaul.asp |title=Micrsoft C# FAQ |publsher=[[Micrsoft]] |aces-date=Marc 25, 2008 |url-status=dea |archiv-url=htps://web.arhive.org/web/20060214002638/htpp://msdn.micrsoft.com/vcsharp/previus/2002/FAQ/defaul.asp |archiv-date=Februry 14, 2006 |df=mdy }}</ref> This convenion is refectd in the ECMA-334 C# Laguage Specifcaion.<ref name="ECMA-334"/> The "sarp" sufic has ben usd by a numbr of othr Micrsoft [[.NET]] compatble/complant laguages that are variaants of existng laguages, includng [[J Sharp|J#]] (a .NET laguage also designd by Micrsoft that is derivd from [[Java (programmn language)|Jva]] 1.1), [[A Sharp (.NET)|A#]] (from [[Ada (programmn language)|Ada]]), and the [[funcional programmn]] laguage [[F Sharp (programmn language)|F#]].<ref name="MS FSharp FAQ">{{cite web |url=htpp://resarc.micrsoft.com/en-us/um/cambridg/projcts/fsharp/faq.asp |title=F# FAQ |publsher=Micrsoft Resarc |aces-date=June 18, 2009 |url-status=dea |archiv-url=htps://web.arhive.org/web/20090218222543/htpp://resarc.micrsoft.com/en-us/um/cambridg/projcts/fsharp/faq.asp |archiv-date=Februry 18, 2009 |df=mdy }}</ref> The origial implemntaton of [[EiffelStudio|Eiffel for .NET]] was caled [[EiffelStudio|Eiffel#]],<ref>{{cite web |url= htpp://msdn.micrsoft.com/en-us/librry/ms973898.asp |title= Ful Eiffel on the .NET Framewor |dat= June 2002 |firs1= Raphal |las1= Simon |firs2= Emmanul |las2= Stapf |firs3= Berand |las3= Meye |publsher= [[Micrsoft]] |aces-date= June 18, 2009 |archiv-date= July 21, 2009 |archiv-url= htps://web.arhive.org/web/20090721131102/htpp://msdn.micrsoft.com/en-us/librry/ms973898.asp |url-status= liv }}</ref> a nam reired sinc the ful [[Eiffel (programmn language)|Eiffel]] laguage is now suorted. The sufic has also ben usd for [[Library (computng)|librarie]], such as [[Gtk Sharp|Gtk#]] (a .NET [[Wrapr patrn|wrapr]] for [[GTK]] and othr [[GNOME]] librarie) and [[Cocoa Sharp|Cocoa#]] (a wrapr for [[Cocoa (API)|Cocoa]]). ===Versios=== Developmnt of the tex for standrds (bginning with C# 6) is don on [htps://gihub.com/dotne/csrstandard GitHub]. C# 7 was submittd to [[Ecma Internaional|Ecma]] and appoved in Decmber 2023. As of Janury 2024, the standrd for C# 8 is curently under developmnt, referncing the [htps://gihub.com/dotne/csrplang/tre/main/proposls appoved laguage proposls]. {| clas="wikitabl" |- ! scop="col" rowspa="2" | C#<br/>versin ! scop="colgrp" colspa="3" | Laguage specifcaion ! scop="col" rowspa="2" | Dat ! scop="col" rowspa="2" | .NET ! scop="col" rowspa="2" | [[Viusl Studio]] |- ! scop="col" | [[Ecma Internaional|Ecma]] ! scop="col" | [[ISO/IEC]] ! scop="col" | [[Micrsoft]] |- | scop="row" | 1.0 | rowspa="2" | ECMA-334:2003, [htps://ecma-internaional.org/wp-cotnt/uploads/ECMA-334_2nd_edtion_decmber_2002.pdf Decmber 2002] | rowspa="2" | ISO/IEC 23270:2003, [htps://stor.acuristeh.com/ieee/standrds/incit-iso-iec-23270-2003?produc_id=1157805 Aprl 2003] | [htpp://download.micrsoft.com/download/a/9/e/a9e229b9-fe5-4c3e-8476-917de385062/CShar%20Laguage%20Specifcaion%20v1.0.doc Janury 2002] | Janury 2002 | [[.NET Framewor versin histoy#.NET Framewor 1.0|.NET Framewor 1.0]] | [[Viusl Studio .NET|Viusl Studio .NET 2002]] |- | scop="row" | 1.1<br/>1.2 | [htpp://download.micrsoft.com/download/5/e/5/5e58be0a-b02b-41ac-a4a3-7a22286214ff/cshar%20laguage%20specifcaion%20v1.2.doc Octber 2003] | Aprl 2003 | {{ubl|[[.NET Framewor 1.1]]}} | [[Viusl Studio .NET 2003]] |- | scop="row" | [[C Sharp 2.0|2.0]]<ref>{{cite web|title=Wat's ne in the C# 2.0 Laguage and Comiler|url=htpp://msdn.micrsoft.com/en-us/librry/7cz8t42e(v=vs.80).asp|publsher=Micrsoft|archiv-url = htps://web.arhive.org/web/20101218191709/htpp://msdn.micrsoft.com/en-us/librry/7cz8t42e(v=vs.80).asp|aces-date=11 June 2014|archiv-date = Decmber 18, 2010}}</ref> | ECMA-334:2006, [htps://ecma-internaional.org/wp-cotnt/uploads/ECMA-334_4th_edtion_june_2006.pdf June 2006] | ISO/IEC 23270:2006, [htpp://standrds.iso.org/itf/PubiclyAvailbleStandrds/c042926_ISO_IEC_23270_2006(E).zp Sepember 2006] | [htpp://download.micrsoft.com/download/9/8/f/98fdf0c7-2bbd-40d3-9fd1-5a4159fa8044/cshar%202.0%20specifcaion_sep_2005.doc Sepember 2005]{{efn|The Micrsoft C# 2.0 specifcaion documnt only contins the ne 2.0 fetures. For older fetures, us the 1.2 specifcaion abov.}} | Novemer 2005 | {{ubl|[[.NET Framewor 2.0]]|[[.NET Framewor 3.0]]}} | [[Viusl Studio 2005]]<br />[[Viusl Studio 2008]] |- | scop="row" | [[C Sharp 3.0|3.0]]<ref>{{cite web|las1=Hejlsberg|firs1=Ander|las2=Torgesn|firs2=Mads|title=Overvew of C# 3.0|url=htpp://https://www.google.com/search?q=msdn.micrsoft.com/en-us/librry/bb308966.asp|websit=Micrsoft Develper Networ|dat=Aprl 30, 2007|publsher=Micrsoft|aces-date=11 June 2014|archiv-date=June 25, 2014|archiv-url=htps://web.arhive.org/web/20140625123055/htpp://https://www.google.com/search?q=msdn.micrsoft.com/en-us/librry/bb308966.asp|url-status=liv}}</ref> | colspa="2" rowspa="2" {{no|Non}} | [htpp://https://www.google.com/search?q=download.micrsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CShar%2520Laguage%2520Specifcaion.doc Augus 2007] | Novemer 2007 | {{ubl|.NET Framewor 2.0 (Exceppt LINQ)<ref name="danielmoth1">{{cite web |url=htpp://https://www.google.com/search?q=www.danelmot.com/Blog/usng-c-30-from-net-20.asp |title=Usng C# 3.0 from .NET 2.0 |publsher=https://www.google.com/search?q=Danelmot.com |dat=May 13, 2007 |aces-date=Octber 4, 2012 |archiv-date=Sepember 29, 2012 |archiv-url=htps://web.arhive.org/web/20120929075553/htpp://https://www.google.com/search?q=www.danelmot.com/Blog/Usng-C-30-From-NET-20.asp |url-status=li |
|||
[[Category:Ecma standards]] |
|||
[[Category:Functional languages]] |
|||
[[Category:IEC standards]] |
|||
[[Category:ISO standards]] |
|||
[[Category:Microsoft programming languages]] |
|||
[[Category:Multi-paradigm programming languages]] |
|||
[[Category:Programming languages created in 2000]] |
|||
[[Category:Programming languages with an ISO standard]] |
|||
[[Category:Statically typed programming languages]] |
|||
[[Category:Compiled programming languages]] |
|||
<!-- Hidden categories below --> |
|||
[[Category:Articles with example C Sharp code]] |
Revision as of 03:09, 4 June 2025
C# | |
---|---|
![]() | |
Paradigm | Multi-paradigm: structured, imperative, object-oriented, event-driven, task-driven, functional, generic, reflective, concurrent |
Family | C |
Designed by | Anders Hejlsberg (Microsoft) |
Developer | Mads Torgersen (Microsoft) |
First appeared | 2000[1] |
Stable release | 14.0[2] ![]() |
Typing discipline | Static, dynamic,[3] strong, safe, nominative, partly inferred |
Memory management | automatic memory management |
Platform | Common Language Infrastructure |
License | |
Filename extensions | .cs , .csx |
Website | learn |
Major implementations | |
Visual C#, .NET, Mono, Universal Windows Platform Discontinued: .NET Framework, DotGNU | |
Dialects | |
Cω, Polyphonic C#, Enhanced C# | |
Influenced by | |
C++,[6] Cω, Eiffel, F#,[a] Haskell, Scala, Icon, J#, J++, Java,[6] JavaScript, ML, Modula-3, Object Pascal,[7] VB | |
Influenced | |
Chapel,[8] Clojure,[9] Crystal,[10] D, J#, Dart,[11] F#, Hack, Java,[12][13] Kotlin, Nemerle, Oxygene, Rust,[14] Swift,[15] Vala, TypeScript | |
|
C# (pronounced: C-sharp) (/ˌsiː ˈʃɑːrp/ see SHARP)[b] is a general-purpose high-level programming language supporting multiple paradigms. C# encompasses static typing,[16]: 4 strong typing, lexically scoped, imperative, declarative, functional, generic,[16]: 22 object-oriented (class-based), and component-oriented programming disciplines.[17]
The principal inventors of the C# programming language were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde from Microsoft.[17] It was first widely distributed in July 2000[17] and was later approved as an international standard by Ecma (ECMA-334) in 2002 and ISO/IEC (ISO/IEC 23270 and 20619[c]) in 2003. Microsoft introduced C# along with .NET Framework and Microsoft Visual Studio, both of which are technically speaking, closed-source. At the time, Microsoft had no open-source products. Four years later, in 2004, a free and open-source project called Microsoft Mono began, providing a cross-platform compiler and runtime environment for the C# programming language. A decade later, Microsoft released Visual Studio Code (code editor), Roslyn (compiler), and the unified .NET platform (software framework), all of which support C# and are free, open-source, and cross-platform. Mono also joined Microsoft but was not merged into .NET.
As of January 2025,[update] the most recent stable version of the language is C# 13.0, which was released in 2024 in .NET 9.0[18][19]
Design goals
The Ecma standard lists these design goals for C#:[17]
- The 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 checking,[20]: 58–59 detection of attempts to use uninitialized variables, and automatic garbage collection.[20]: 563 Software robustness, durability, and programmer productivity are important.
- The language is intended for use in developing software components suitable for deployment in distributed environments.
- Portability is very important for source code and programmers, especially those already familiar with C and C++.
- Support for internationalization[20]: 314 is very important.
- C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions.
- Although C# applications are intended to be economical with regard to memory and processing power requirements, the language was not intended to compete directly on performance and size with C or assembly language.[21]
History
During the development of the .NET Framework, the class libraries were originally written using a managed code compiler system named Simple Managed C (SMC).[22][23] 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".[24] Microsoft had considered keeping the name "COOL(C-like Object Oriented Language)" 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 were ported to C#.
Hejlsberg is C#'s principal designer and lead architect at Microsoft, and was previously involved with the design of Turbo Pascal, Embarcadero Delphi (formerly CodeGear Delphi, Inprise Delphi and Borland Delphi), and Visual J++. In interviews and technical papers, he has stated that flaws[25] 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.
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 said that "[C# is] sort of Java with reliability, productivity and security deleted."[26][27] In July 2000, Hejlsberg said that C# is "not a Java clone" and is "much closer to C++" in its design.[28]
Since the release of C# 2.0 in November 2005, the C# and Java languages have evolved on increasingly divergent trajectories, becoming two quite different languages. One of the first major departures came with the addition of generics to both languages, with vastly different implementations. C# uses of reification to provide "first-class" generic objects that can be used like any other class, with code generation performed at class-load time.[29] Furthermore, C# has added several major features to accommodate functional-style programming, culminating in the LINQ extensions released with C# 3.0 and its supporting framework of lambda expressions, extension methods, and anonymous types.[30] 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 included in common tasks such as 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.[31]
C# used to have a mascot called Andy (named after Anders Hejlsberg). It was retired on January 29, 2004.[32]
C# was originally submitted to the ISO/IEC JTC 1 subcommittee SC 22 for review,[33] under ISO/IEC 23270:2003,[34] was withdrawn and was then approved under ISO/IEC 23270:2006.[35] The 23270:2006 is withdrawn under 23270:2018 and approved with this version.[36]
Name
Microsoft first used the name C# in 1988 for a variant of the C language designed for incremental compilation.[37] That project was not completed, and the name was later reused.

The name "C sharp" was inspired by the musical notation whereby a sharp symbol indicates that the written note should be made a semitone higher in pitch.[38] This is similar to the language name of C++, where "++" indicates that a variable should be incremented by 1 after being evaluated. 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++.[39]
Due to technical limits of display (standard fonts, browsers, etc.), and most keyboard layouts lacking a sharp symbol (U+266F ♯ MUSIC SHARP SIGN (♯)), the number sign (U+0023 # NUMBER SIGN (#)) was chosen to approximate the sharp symbol in the written name of the programming language.[40] This convention is reflected in the ECMA-334 C# Language Specification.[17]
The "sharp" suffix has been used by a number of other Microsoft .NET compatible/compliant 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#.[41] The original implementation of Eiffel for .NET was called Eiffel#,[42] a name 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) and Cocoa# (a wrapper for Cocoa).
Versions
Development of the text for standards (beginning with C# 6) is done on GitHub. C# 7 was submitted to Ecma and approved in December 2023. As of January 2024, the standard for C# 8 is currently under development, referencing the approved language proposals.
Syntax
The core syntax of the C# language is similar to that of other C-style languages such as C, Objective-C, C++ and Java, particularly:
- Semicolons are used to denote the end of a statement.
- Curly brackets are used to group statements. Statements are commonly grouped into methods (functions), methods into classes, and classes into namespaces.
- Variables are assigned using an equals sign, but compared using two consecutive equals signs.
- Square brackets are used with arrays, both to declare them and to get a value at a given index in one of them.
- "class", "int" and "void" are used to define large-scale (usually main) program functions in scripts most of the time in C-style computer programming languages.
Distinguishing features
Some notable features of C# that distinguish it from C, C++, and Java where noted, are:
Portability
By design, C# is the programming language that most directly reflects the underlying Common Language Infrastructure (CLI).[70] Most of its intrinsic types correspond to value-types implemented by the CLI (Common Language Infrastructure) 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 (CLR), or generate Common Intermediate Language (CIL), or generate any other specific format. Some C# compilers can also generate machine code like traditional compilers of Objective-C, C, C++, Assembly and Fortran.[71][72]
Typing
C# supports strongly, implicitly typed variable declarations with the keyword var
,[16]: 470 and implicitly typed arrays with the keyword new[]
followed by a collection initializer.[16]: 80 [20]: 58
Its type system is split into two families: Value types, like the built-in numeric types and user-defined structs, which are automatically handed over as copies when used as parameters, and reference types, including arrays, instances of classes, and strings, which only hand over a pointer to the respective object. Due to their special handling of the equality operator and their immutability, strings will nevertheless behave as if they were values, for all practical purposes. You can even use them as case labels. Where necessary, value types will be boxed automatically.[73]
C# supports a strict Boolean data type, bool
. Statements that take conditions, such as while
and if
, require an expression of a type that implements the true
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 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 assignment =
instead of equality ==
).
C# is more type safe 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 JIT, 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 constructors and conversion operators, which are both implicit by default.
C# has explicit support for covariance and contravariance in generic types,[16]: 144 [20]: 23 unlike C++ which has some degree of support for contravariance simply through the semantics of return types on virtual methods.
Enumeration members are placed in their own scope.
The C# language does not allow for 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++, but may shadow type-level names.
Metaprogramming
Metaprogramming can be achieved in several ways:
- Reflection is supported through .NET APIs, which enable scenarios such as type metadata inspection and dynamic method invocation.
- Expression trees[74] represent code as an abstract syntax tree, where each node is an expression that can be inspected or executed. This enables dynamic modification of executable code at runtime. Expression trees introduce some homoiconicity to the language.
- Attributes, in C# parlance, are metadata that can be attached to types, members, or entire assemblies, equivalent to annotations in Java. Attributes are accessible both to the compiler and to code through reflection, allowing them to adjust their behaviour.[75] Many of the native attributes duplicate the functionality of GCC's and VisualC++'s platform-dependent preprocessor directives.[citation needed]
System.Reflection.Emit
namespace,[76] which contains classes that emit metadata and CIL (types, assemblies, etc.) at runtime.- The .NET Compiler Platform (Roslyn) provides API access to language compilation services, allowing for the compilation of C# code from within .NET applications. It exposes APIs for syntactic (lexical) analysis of code, semantic analysis, dynamic compilation to CIL, and code emission.[77]
- Source generators,[78] a feature of the Roslyn C# compiler, enable compile time metaprogramming. During the compilation process, developers can inspect the code being compiled with the compiler's API and pass additional generated C# source code to be compiled.
Methods and functions
A method in C# is a member of a class that can be invoked as a function (a sequence of instructions), rather than the mere value-holding capability of a field (i.e. class or instance variable).[79] As in other syntactically similar languages, such as C++ and ANSI C, the signature of a method is a declaration comprising in order: any optional accessibility keywords (such as private
), the explicit specification of its return type (such as int
, or the keyword void
if no value is returned), the name of the method, and finally, a parenthesized sequence of comma-separated parameter specifications, each consisting of a parameter's type, its formal name and optionally, a default value to be used whenever none is provided. Different from most other languages, call-by-reference parameters have to be marked both at the function definition and at the calling site, and you can choose between ref
and out
, the latter allowing handing over an uninitialized variable which will have a definite value on return.[80] Additionally, you can specify a variable-sized argument list by applying the params
keyword to the last parameter.[81] Certain specific kinds of methods, such as those that simply get or set a field's value by returning or assigning it, do not require an explicitly stated full signature, but in the general case, the definition of a class includes the full signature declaration of its methods.[82]
Like C++, and unlike Java, C# programmers must use the scope modifier keyword virtual
to allow methods to be overridden by subclasses. Unlike C++, you have to explicitly specify the keyword override
when doing so.[83] This is supposed to avoid confusion between overriding and newly overloading a function (i.e. hiding the former implementation). To do the latter, you have to specify the new
keyword.[84] You can use the keyword sealed
to disallow further overrides for individual methods or whole classes.[85]
Extension methods in C# allow programmers to use static methods as if they were methods from a class's method table, allowing programmers to virtually add instance methods to a class that they feel should exist on that kind of objects (and instances of the respective derived classes).[16]: 103–105 [20]: 202–203
The type dynamic
allows for run-time method binding, allowing for JavaScript-like method calls and run-time object composition.[16]: 114–118
C# has support for strongly-typed function pointers via the keyword delegate
. Like the Qt framework's pseudo-C++ signal and slot, C# has semantics specifically surrounding publish-subscribe style events, though C# uses delegates to do so.
C# offers Java-like synchronized
method calls, via the attribute [MethodImpl(MethodImplOptions.Synchronized)]
, and has support for mutually-exclusive locks via the keyword lock
.
Property
C# supports classes with properties. The properties can be simple accessor functions with a backing field, or implement arbitrary getter and setter functions. A property is read-only if there's no setter. Like with fields, there can be class and instance properties. The underlying methods can be virtual
or abstract
like any other method.[82]
Since C# 3.0 the syntactic sugar of auto-implemented properties is available,[86] where the accessor (getter) and mutator (setter) encapsulate operations on a single field of a class.
Namespace
A C# namespace
provides the same level of code isolation as a Java package
or a C++ namespace
, with very similar rules and features to a package
. Namespaces can be imported with the "using" syntax.[87]
Memory access
In C#, memory address pointers can only be used within blocks specifically marked as unsafe,[88] 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 an arbitrary block of memory. An unsafe pointer can point to an instance of an unmanaged value type that does not contain any references to objects subject to garbage collections such as class instances, arrays or strings. 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 the problem of memory leaks by freeing the programmer of responsibility for releasing memory that is no longer needed in most cases. Code that retains references to objects longer than is required can still experience higher memory usage than necessary, however once the final reference to an object is released the memory is available for garbage collection.
Exceptions
A range of standard exceptions are available to programmers. Methods in standard libraries regularly throw system exceptions in some circumstances and the range of exceptions thrown is normally documented. Custom exception classes can be defined for classes allowing handling to be put in place for particular circumstances as needed.[89]
The syntax for handling exceptions is the following:
try
{
// something
}
catch (Exception ex)
{
// if error do this
}
finally
{
// always executes, regardless of error occurrence
}
Most of the time people call this a "try-catch" code block, because of the "try" and "catch" functions being used and accessible on all C# versions.
try
{
// something here
}
catch (Exception ex)
{
// example
return 0;
}
finally
{
return 1;
}
Depending on your plans, the "finally" part can be left out. If error handling is not required, the (Exception ex)
parameter can be omitted as well. Also, there can be several "catch" parts handling different kinds of exceptions.[90]
Checked exceptions are not present in C# (in contrast to Java). This has been a conscious decision based on the issues of scalability and version management.[91]
Polymorphism
Unlike C++, C# does not support multiple inheritance, although a class can implement any number of "interfaces" (fully abstract classes). This was a design decision by the language's lead architect to avoid complications and to simplify architectural requirements throughout CLI.
When implementing multiple interfaces that contain a method with the same name and taking parameters of the same type in the same order (i.e. the same signature), similar to Java, C# allows both a single method to cover all interfaces and if necessary specific methods for each interface.
C# also offers function overloading (a.k.a. ad-hoc-polymorphism), i.e. methods with the same name, but distinguishable signatures.[92] Unlike Java, C# additionally supports operator overloading.[93]
Since version 2.0, C# offers parametric polymorphism, i.e. classes with arbitrary or constrained type parameters, e.g. List<T>
, a variable-sized array which only can contain elements of type T
. There are certain kinds of constraints you can specify for the type parameters: Has to be type X (or one derived from it), has to implement a certain interface, has to be a reference type, has to be a value type, has to implement a public parameterless constructor. Most of them can be combined, and you can specify any number of interfaces.[94][95]
Language Integrated Query (LINQ)
C# has the ability to utilize LINQ through the .NET Framework. A developer can query a variety of data sources, provided the IEnumerable<T>
interface is implemented on the object. This includes XML documents, an ADO.NET dataset, and SQL databases.[96]
Using LINQ in C# brings advantages like IntelliSense support, strong filtering capabilities, type safety with compile error checking ability, and consistency for querying data over a variety of sources.[97] There are several different language structures that can be utilized with C# and LINQ and they are query expressions, lambda expressions, anonymous types, implicitly typed variables, extension methods, and object initializers.[98]
LINQ has two syntaxes: query syntax and method syntax. However, the compiler always converts the query syntax to method syntax at compile time.[99]
using System.Linq;
var numbers = new int[] { 5, 10, 8, 3, 6, 12 };
// Query syntax (SELECT num FROM numbers WHERE num % 2 = 0 ORDER BY num)
var numQuery1 =
from num in numbers
where num % 2 == 0
orderby num
select num;
// Method syntax
var numQuery2 =
numbers
.Where(num => num % 2 == 0)
.OrderBy(n => n);
Functional programming
Though primarily an imperative language, C# always adds functional features over time,[100][101] for example:
- Functions as first-class citizen – C# 1.0 delegates[102]
- Higher-order functions – C# 1.0 together with delegates
- Anonymous functions – C# 2 anonymous delegates and C# 3 lambdas expressions[103]
- Closures – C# 2 together with anonymous delegates and C# 3 together with lambdas expressions[103]
- Type inference – C# 3 with implicitly typed local variables
var
and C# 9 target-typed new expressionsnew()
- List comprehension – C# 3 LINQ
- Tuples – .NET Framework 4.0 but it becomes popular when C# 7.0 introduced a new tuple type with language support[104]
- Nested functions – C# 7.0[104]
- Pattern matching – C# 7.0[104]
- Immutability – C# 7.2 readonly struct C# 9 record types[105] and Init only setters[106]
- Type classes – C# 12 roles/extensions (in development[107])
Common type system
C# has a unified type system. This unified type system is called Common Type System (CTS).[108]: Part 2, Chapter 4: The Type System
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.
Categories of data types
CTS separates data types into two categories:[108]
- Reference types
- Value types
Instances of value types neither 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 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 an explicit default (parameterless) constructor because they already have an implicit one which initializes all contained data to the type-dependent default value (0, null, or alike). Examples of value types are all 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), decimal
(fixed-point numbers useful for handling currency amounts), and System.DateTime
(identifies a specific point in time with nanosecond precision). Other examples are enum
(enumerations) and struct
(user defined structures).
In contrast, reference types have the notion of referential identity, meaning that 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 System.String
). Some operations are not always possible, such as creating an instance of a reference type, copying an existing instance, or performing a value comparison on two existing instances. Nevertheless, 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-type object into a value of a corresponding reference type.[108] 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.[108] 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).[109]
Example:
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.
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).
In addition to the standard CLI specifications, there are many commercial and community class libraries that build on top of the .NET framework libraries to provide additional functionality.[110]
C# can make calls to any library included in the List of .NET libraries and frameworks.
Examples
Hello World
The following is a very simple C# program, a version of the classic "Hello world" example using the top-level statements feature introduced in C# 9:[111]
System.Console.WriteLine("Hello, world!");
For code written as C# 8 or lower, the entry point logic of a program must be written in a Main method inside a type:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, world!");
}
}
This code will display this text in the console window:
Hello, world!
Each line has a purpose:
using System;
The above line imports all types in the System
namespace. For example, the Console
class used later in the source code is defined in the System
namespace, meaning it can be used without supplying the full name of the type (which includes the namespace).
// A version of the classic "Hello World" program
This line is a comment; it describes and documents the code for the programmer(s).
class Program
Above is a class definition for the Program
class. Everything that follows between the pair of braces describes that class.
{
...
}
The curly brackets demarcate the boundaries of a code block. In this first instance, they are marking the start and end of the Program
class.
static void Main()
This declares the class member method where the program begins execution. The .NET runtime calls the Main
method. Unlike in Java, the Main
method does not need the public
keyword, which tells the compiler that the method can be called from anywhere by any class.[112] Writing static void Main(string[] args)
is equivalent to writing private static void Main(string[] args)
. The static keyword makes the method accessible without an instance of Program
. Each console application's Main
entry point must be declared static
otherwise the program would require an instance of Program
, 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 static Main
method. The void
keyword declares that Main
has no return value. (Note, however, that short programs can be written using Top Level Statements introduced in C# 9, as mentioned earlier.)
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!"
.
Generics
With .NET 2.0 and C# 2.0, the community got more flexible collections than those in .NET 1.x. In the absence of generics, developers had to use collections such as ArrayList to store elements as objects of unspecified kind, which incurred performance overhead when boxing/unboxing/type-checking the contained items.
Generics introduced a massive new feature in .NET that allowed developers to create type-safe data structures. This shift is particularly important in the context of converting legacy systems, where updating to generics can significantly enhance performance and maintainability by replacing outdated data structures with more efficient, type-safe alternatives.[113]
Example
public class DataStore<T>
{
private T[] items = new T[10];
private int count = 0;
public void Add(T item)
{
items[count++] = item;
}
public T Get(int index)
{
return items[index];
}
}
Standardization and licensing
In August 2001, Microsoft, Hewlett-Packard and Intel 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/IEC 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 (somewhat similar to C++ templates). In July 2005, ECMA submitted to ISO/IEC JTC 1/SC 22, via the latter's Fast-Track process, the standards and related TRs. This process usually takes 6–9 months.
The C# language definition and the CLI are standardized under ISO/IEC and Ecma standards that provide reasonable and non-discriminatory licensing protection from patent claims.
Microsoft initially 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 Open Specification Promise.[114] Microsoft has also agreed not to enforce patents relating to Novell products against Novell's paying customers[115] with the exception of a list of products that do not explicitly mention C#, .NET or Novell's implementation of .NET (The Mono Project).[116] However, Novell maintained that Mono does not infringe any Microsoft patents.[117] Microsoft 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.[118]
A decade later, Microsoft began developing free, open-source, and cross-platform tooling for C#, namely Visual Studio Code, .NET Core, and Roslyn. Mono joined Microsoft as a project of Xamarin, a Microsoft subsidiary.
Implementations
Microsoft has developed open-source reference C# compilers and tools. The first compiler, Roslyn, compiles into intermediate language (IL), and the second one, RyuJIT,[119] is a JIT (just-in-time) compiler, which is dynamic and does on-the-fly optimization and compiles the IL into native code for the front-end of the CPU.[120] RyuJIT is open source and written in C++.[121] Roslyn is entirely written in managed code (C#), has been opened up and functionality surfaced as APIs. It is thus enabling developers to create refactoring and diagnostics tools.[4][122] Two branches of official implementation are .NET Framework (closed-source, Windows-only) and .NET Core (open-source, cross-platform); they eventually converged into one open-source implementation: .NET 5.0.[123] At .NET Framework 4.6, a new JIT compiler replaced the former.[119][124]
Other C# compilers (some of which include an implementation of the Common Language Infrastructure and .NET class libraries):
- Mono, a Microsoft-sponsored project provides an open-source C# compiler, a complete open-source implementation of the CLI (including the required framework libraries as they appear in the ECMA specification,) and a nearly complete implementation of the NET class libraries up to .NET Framework 3.5.
- The Elements tool chain from RemObjects includes RemObjects C#, which compiles C# code to .NET's Common Intermediate Language, Java bytecode, Cocoa, Android bytecode, WebAssembly, and native machine code for Windows, macOS, and Linux.
- The DotGNU project (now discontinued) also provided 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 Unity game engine uses C# as its primary scripting language. The Godot game engine has implemented an optional C# module due to a donation of $24,000 from Microsoft.[125]
See also
- C# topics
- IDEs
Notes
- ^ for async
- ^ By convention, a number sign is used for the second character in normal text; in artistic representations, sometimes a true sharp sign is used: C♯. However the ECMA 334 standard states: "The name C# is written as the LATIN CAPITAL LETTER C (U+0043) followed by the NUMBER SIGN # (U+0023)."
- ^ Language versions 1.0, 2.0, and 5.0 are available as ISO/IEC 23270. Beginning with version 7.0, the specification is available as ISO/IEC 20619
- ^ The Microsoft C# 2.0 specification document only contains the new 2.0 features. For older features, use the 1.2 specification above.
References
Citations
- ^ "InfoQ eMag: A Preview of C# 7". Archived from the original on April 24, 2023. Retrieved November 11, 2016.
- ^ https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-10/overview.
{{cite web}}
: Missing or empty|title=
(help) - ^ Torgersen, Mads (October 27, 2008). "New features in C# 4.0". Microsoft. Archived from the original on January 3, 2012. Retrieved October 28, 2008.
- ^ a b "The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.: dotnet/roslyn". November 13, 2019. Archived from the original on February 22, 2021. Retrieved February 13, 2015 – via GitHub.
- ^ "CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes.: dotnet/coreclr". November 13, 2019. Archived from the original on October 14, 2019. Retrieved March 8, 2017 – via GitHub.
- ^ a b Naugler, David (May 2007). "C# 2.0 for C++ and Java programmer: conference workshop". Journal of Computing Sciences in Colleges. 22 (5).
Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.
- ^ Hamilton, Naomi (October 1, 2008). "The A-Z of Programming Languages: C#". Computerworld. Archived from the original on March 24, 2010. Retrieved February 12, 2010.
We all stand on the shoulders of giants here and every language builds on what went before it so we owe a lot to C, C++, Java, Delphi, all of these other things that came before us. (Anders Hejlsberg)
- ^ "Chapel spec (Acknowledgments)" (PDF). Cray Inc. October 1, 2015. Archived from the original (PDF) on February 5, 2016. Retrieved January 14, 2016.
- ^ "Rich Hickey Q&A by Michael Fogus". Archived from the original on January 11, 2017. Retrieved January 11, 2017.
- ^ Borenszweig, Ary (June 14, 2016). "Crystal 0.18.0 released!". Archived from the original on December 25, 2018. Retrieved August 7, 2017.
It's heavily inspired by Ruby, and other languages (like C#, Go and Python).
- ^ "Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013". YouTube. May 16, 2013. Archived from the original on December 21, 2021. Retrieved December 22, 2013.
- ^ Java 5.0 added several new language features (the enhanced for loop, autoboxing, varargs and annotations), after they were introduced in the similar (and competing) C# language [1] Archived March 19, 2011, at the Wayback Machine [2] Archived January 7, 2006, at the Wayback Machine
- ^ Cornelius, Barry (December 1, 2005). "Java 5 catches up with C#". University of Oxford Computing Services. Archived from the original on March 6, 2023. Retrieved June 18, 2014.
In my opinion, it is C# that has caused these radical changes to the Java language. (Barry Cornelius)
- ^ "Influences - The Rust Reference". The Rust Reference. Archived from the original on January 26, 2019. Retrieved April 18, 2023.
- ^ Lattner, Chris (June 3, 2014). "Chris Lattner's Homepage". Chris Lattner. Archived from the original on December 25, 2018. Retrieved May 12, 2020.
The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.
- ^ a b c d e f g Skeet 2019.
- ^ a b c d e C# Language Specification (PDF) (4th ed.). Ecma International. June 2006. Archived (PDF) from the original on April 21, 2021. Retrieved January 26, 2012.
- ^ Dollard, Kathleen (November 14, 2023). "Announcing C# 12". .NET Blog. Archived from the original on November 18, 2023. Retrieved November 18, 2023.
- ^ Seth, Gaurav (November 14, 2023). "Announcing .NET 8". .NET Blog. Archived from the original on November 19, 2023. Retrieved November 18, 2023.
- ^ a b c d e f Albahari 2022.
- ^ "Design Goals of C#". www.java-samples.com. Archived from the original on October 6, 2021. Retrieved October 6, 2021.
- ^ Zander, Jason (November 22, 2007). "Couple of Historical Facts". Archived from the original on July 29, 2020. Retrieved February 23, 2009.
- ^ "What language was ASP.Net originally written in?". November 28, 2006. Archived from the original on June 24, 2016. Retrieved February 21, 2008.
- ^ Hamilton, Naomi (October 1, 2008). "The A-Z of Programming Languages: C#". Computerworld. Archived from the original on May 18, 2019. Retrieved October 1, 2008.
- ^ "Details". nilsnaegele.com. Archived from the original on April 7, 2019. Retrieved April 7, 2019.
- ^ "Why Microsoft's C# isn't". CNET: CBS Interactive. 2002. Archived from the original on August 14, 2023. Retrieved September 18, 2023.
- ^ Bill Joy (February 7, 2002). "Microsoft's blind spot". cnet.com. Archived from the original on August 14, 2023. Retrieved September 18, 2023.
- ^ Osborn, John (August 1, 2000). "Deep Inside C#: An Interview with Microsoft Chief Architect Anders Hejlsberg". O'Reilly Media. Archived from the original on January 9, 2010. Retrieved November 14, 2009.
- ^ "Generics (C# Programming Guide)". Microsoft. Archived from the original on August 26, 2011. Retrieved March 21, 2011.
- ^ Don Box and Anders Hejlsberg (February 2007). "LINQ: .NET Language-Integrated Query". Microsoft. Archived from the original on August 24, 2011. Retrieved March 21, 2011.
- ^ Mercer, Ian (April 15, 2010). "Why functional programming and LINQ is often better than procedural code". abodit.com. Archived from the original on July 11, 2011. Retrieved March 21, 2011.
- ^ "Andy Retires". Dan Fernandez's Blog. Blogs.msdn.com. January 29, 2004. Archived from the original on January 19, 2016. Retrieved October 4, 2012.
- ^ "Technical committees - JTC 1/SC 22 - Programming languages, their environments and system software interfaces". ISO. Archived from the original on September 27, 2012. Retrieved October 4, 2012.
- ^ "ISO/IEC 23270:2003 - Information technology - C# Language Specification". Iso.org. August 23, 2006. Archived from the original on May 8, 2012. Retrieved October 4, 2012.
- ^ "ISO/IEC 23270:2006 - Information technology - Programming languages - C#". Iso.org. January 26, 2012. Archived from the original on December 6, 2010. Retrieved October 4, 2012.
- ^ "SO/IEC 23270:2018 Information technology — Programming languages — C#". ISO. Retrieved November 26, 2020.
- ^ Mariani, Rico (October 5, 2009). "My History of Visual Studio (Part 1) – Rico Mariani's Performance Tidbits". Rico Mariani's Performance Tidbits. Archived from the original on May 27, 2018. Retrieved May 26, 2018.
- ^ Kovacs, James (September 7, 2007). "C#/.NET History Lesson". Archived from the original on March 6, 2009. Retrieved June 18, 2009.
- ^ Hejlsberg, Anders (October 1, 2008). "The A-Z of Programming Languages: C#". Computerworld. Archived from the original on April 2, 2015. Retrieved June 22, 2014.
- ^ "Microsoft C# FAQ". Microsoft. Archived from the original on February 14, 2006. Retrieved March 25, 2008.
- ^ "F# FAQ". Microsoft Research. Archived from the original on February 18, 2009. Retrieved June 18, 2009.
- ^ Simon, Raphael; Stapf, Emmanuel; Meyer, Bertrand (June 2002). "Full Eiffel on the .NET Framework". Microsoft. Archived from the original on July 21, 2009. Retrieved June 18, 2009.
- ^ "What's new in the C# 2.0 Language and Compiler". Microsoft. Archived from the original on December 18, 2010. Retrieved June 11, 2014.
- ^ Hejlsberg, Anders; Torgersen, Mads (April 30, 2007). "Overview of C# 3.0". Microsoft Developer Network. Microsoft. Archived from the original on June 25, 2014. Retrieved June 11, 2014.
- ^ a b "Using C# 3.0 from .NET 2.0". Danielmoth.com. May 13, 2007. Archived from the original on September 29, 2012. Retrieved October 4, 2012.
- ^ Hejlsberg, Anders (September 15, 2011). "Future directions for C# and Visual Basic". Channel 9. BUILD2011. Microsoft. Archived from the original on September 23, 2011. Retrieved September 21, 2011.
- ^ "An Introduction to New Features in C# 5.0". The Microsoft MVP Award Program Blog. Microsoft. March 26, 2012. Archived from the original on June 4, 2014. Retrieved June 11, 2014.
- ^ "Languages features in C# 6 and VB 14". GitHub. dotnet/roslyn. Archived from the original on January 12, 2016. Retrieved February 13, 2015.
- ^ "What's new in C# 7". Microsoft Docs. December 21, 2016. Archived from the original on November 1, 2017.
- ^ Torgersen, Mads (March 9, 2017). "New Features in C# 7.0". .NET Blog. Microsoft. Archived from the original on April 11, 2017. Retrieved June 9, 2017.
- ^ "Visual Studio 2017 version 15.0 Release Notes". Microsoft Learn. April 11, 2023. Archived from the original on April 20, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 7.1". Microsoft Docs. Archived from the original on October 10, 2017. Retrieved October 9, 2017.
- ^ "Visual Studio 2017 version 15.3 Release Notes". Microsoft Learn. April 11, 2023. Archived from the original on March 21, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 7.2". Microsoft Docs. Archived from the original on December 1, 2017. Retrieved November 26, 2017.
- ^ "Visual Studio 2017 version 15.5 Release Notes". Microsoft Learn. April 11, 2023. Archived from the original on April 20, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 7.3". Microsoft Docs. Archived from the original on June 23, 2018. Retrieved June 23, 2018.
- ^ "Visual Studio 2017 version 15.7 Release Notes". Microsoft Learn. July 13, 2022. Archived from the original on April 20, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 8.0". Microsoft Docs. March 9, 2023. Archived from the original on September 6, 2020. Retrieved April 14, 2019.
- ^ "Visual Studio 2019 version 16.3 Release Notes". Microsoft Learn. April 11, 2023. Archived from the original on April 20, 2023. Retrieved April 19, 2023.
- ^ BillWagner. "What's new in C# 9.0 - C# Guide". Microsoft Learn. Archived from the original on September 5, 2020. Retrieved October 15, 2020.
- ^ "Visual Studio 2019 version 16.8 Release Notes". Microsoft Learn. April 11, 2023. Archived from the original on April 20, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 10". Microsoft Learn. Archived from the original on February 8, 2022. Retrieved November 10, 2021.
- ^ "Visual Studio 2022 version 17.0 Release Notes". Microsoft Learn. Archived from the original on July 16, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 11". Microsoft Learn. Archived from the original on August 15, 2022. Retrieved August 8, 2022.
- ^ "Visual Studio 2022 version 17.4 Release Notes". Microsoft Learn. Archived from the original on August 6, 2023. Retrieved April 19, 2023.
- ^ "What's new in C# 12". Microsoft Learn. Archived from the original on July 20, 2023. Retrieved June 29, 2023.
- ^ "Visual Studio 2022 version 17.8 Release Notes". Microsoft Learn. August 13, 2024. Archived from the original on October 6, 2024. Retrieved November 18, 2024.
- ^ "What's new in C# 13". Microsoft Learn. Archived from the original on November 13, 2024. Retrieved November 18, 2024.
- ^ "Visual Studio 2022 Release Notes". Microsoft Learn. November 12, 2024. Archived from the original on November 12, 2024. Retrieved November 18, 2024.
- ^ Novák et al. 2010.
- ^ stevewhims; mattwojo (October 20, 2022). "Compiling Apps with .NET Native - UWP applications". learn.microsoft.com. Archived from the original on October 27, 2023. Retrieved October 27, 2023.
- ^ LakshanF; agocke; Rick-Anderson; et al. (September 12, 2023). "Native AOT deployment overview - .NET". learn.microsoft.com. Archived from the original on November 11, 2023. Retrieved October 27, 2023.
{{cite web}}
: CS1 maint: numeric names: authors list (link) - ^ "Types/General, part of the official C# documentation". Microsoft. Archived from the original on March 29, 2024. Retrieved April 6, 2024.
- ^ BillWagner. "Expression Trees (C#)". Microsoft Learn. Archived from the original on May 15, 2021. Retrieved May 14, 2021.
- ^ "Attribute Class".
- ^ dotnet-bot. "System.Reflection.Emit Namespace". learn.microsoft.com. Archived from the original on April 28, 2023. Retrieved April 28, 2023.
- ^ McAllister, Neil (October 20, 2011). "Microsoft's Roslyn: Reinventing the compiler as we know it". InfoWorld. Archived from the original on March 5, 2022. Retrieved March 5, 2022.
- ^ "Introducing C# Source Generators". .NET Blog. April 29, 2020. Archived from the original on May 7, 2021. Retrieved May 14, 2021.
- ^ "Classes/fields, part of the official C# documentation". February 7, 2024.
- ^ "out (C# Reference)". March 30, 2024.
- ^ "Method parameters/params modifier, part of the official C# documentation". May 21, 2024.
- ^ a b "Classes/properties, part of the official C# documentation". February 7, 2024.
- ^ "virtual (C# Reference)". Microsoft Learn. September 15, 2021. Archived from the original on August 30, 2018. Retrieved April 4, 2018.
- ^ "new modifier, part of the official C# documentation". April 12, 2023.
- ^ "Abstract and Sealed Classes and Class Members - C#". October 27, 2021.
- ^ "Auto-Implemented Properties (C# Programming Guide)". Archived from the original on October 29, 2020. Retrieved September 12, 2020.
- ^ "using directive - C# Reference". Microsoft Docs. Archived from the original on April 14, 2019. Retrieved April 14, 2019.
- ^ BillWagner. "Unsafe code, pointers to data, and function pointers". Microsoft Learn. Archived from the original on July 4, 2021. Retrieved June 20, 2021.
- ^ "How to create user-defined exceptions". Archived from the original on January 26, 2021. Retrieved September 12, 2020.
- ^ "Exception-handling statements, part of the official C# documentation". Microsoft Learn. April 22, 2023. Retrieved June 26, 2024.
- ^ Venners, Bill; Eckel, Bruce (August 18, 2003). "The Trouble with Checked Exceptions". Archived from the original on February 18, 2015. Retrieved March 30, 2010.
- ^ "Expressions/Overload resolution, part of the official C# documentation". Microsoft Learn. February 7, 2024. Retrieved April 7, 2024.
- ^ BillWagner. "Operator overloading - C# reference". Microsoft Learn. Archived from the original on June 24, 2021. Retrieved June 20, 2021.
- ^ "Types/Constructed Types, part of the official C# documentation". Microsoft Learn. Retrieved April 7, 2024.
- ^ "Classes/Type Parameter constraints, part of the official C# documentation". Microsoft Learn. February 7, 2024. Retrieved April 7, 2024.
- ^ Zhang, Xue Dong; Teng, Zi Mu; Zhao, Dong Wang (September 2014). "Research of the Database Access Technology Under.NET Framework". Applied Mechanics and Materials. 644–650: 3077–3080. doi:10.4028/www.scientific.net/AMM.644-650.3077. S2CID 62201466. ProQuest 1565579768.
- ^ Otey, Michael (February 2006). "LINQ to the Future". SQL Server Magazine. Vol. 8, no. 2. pp. 17–21. ProQuest 214859896.
- ^ Sheldon, William (November 2010). "New Features in LINQ". SQL Server Magazine. Vol. 12, no. 11. pp. 37–40. ProQuest 770609095.
- ^ BillWagner (September 15, 2021). "Query Syntax and Method Syntax in LINQ (C#)". learn.microsoft.com. Archived from the original on May 23, 2023. Retrieved May 23, 2023.
- ^ erikdietrich (March 9, 2023). "The history of C# - C# Guide". learn.microsoft.com. Archived from the original on April 28, 2023. Retrieved April 28, 2023.
- ^ The functional journey of C# - Mads Torgersen - NDC Copenhagen 2022, August 17, 2022, archived from the original on May 15, 2023, retrieved May 15, 2023
- ^ "The Beauty of Closures". csharpindepth.com. Archived from the original on May 19, 2023. Retrieved April 28, 2023.
- ^ a b BillWagner. "Anonymous functions - C# Programming Guide". Microsoft Learn. Archived from the original on April 15, 2021. Retrieved May 15, 2021.
- ^ a b c "What's New in C# 7.0". Microsoft Docs. Archived from the original on August 6, 2020. Retrieved April 14, 2019.
- ^ "C# 9.0 on the record". .NET Blog. November 10, 2020. Archived from the original on May 15, 2021. Retrieved May 15, 2021.
- ^ BillWagner (June 30, 2022). "init keyword - C# Reference". learn.microsoft.com. Archived from the original on May 19, 2023. Retrieved May 19, 2023.
- ^ The .NET Compiler Platform, .NET Platform, April 28, 2023, archived from the original on April 28, 2023, retrieved April 28, 2023
- ^ a b c d Archer 2001.
- ^ Lippert, Eric (March 19, 2009). "Representation and Identity". Fabulous Adventures In Coding. Blogs.msdn.com. Archived from the original on July 12, 2011. Retrieved October 4, 2012.
- ^ "Framework Libraries". Microsoft Learn. April 19, 2023. Archived from the original on July 14, 2019. Retrieved July 14, 2019.
- ^ BillWagner. "What's new in C# 9.0 - C# Guide". Microsoft Learn. Archived from the original on September 5, 2020. Retrieved May 14, 2021.
- ^ BillWagner. "Main() and command-line arguments". Microsoft Learn. Archived from the original on August 5, 2021. Retrieved August 5, 2021.
- ^ "Unlocking the Power of C# Generics: A Comprehensive Guide". April 24, 2024.
- ^ "Patent Pledge for Open Source Developers". March 16, 2023. Archived from the original on December 7, 2017. Retrieved October 28, 2017.
- ^ "Patent Cooperation Agreement - Microsoft & Novell Interoperability Collaboration". Microsoft. November 2, 2006. Archived from the original on May 17, 2009. Retrieved July 5, 2009.
Microsoft, on behalf of itself and its Subsidiaries (collectively "Microsoft"), hereby covenants not to sue Novell's Customers and Novell's Subsidiaries' Customers for infringement under Covered Patents of Microsoft on account of such a Customer's use of specific copies of a Covered Product as distributed by Novell or its Subsidiaries (collectively "Novell") for which Novell has received Revenue (directly or indirectly) for such specific copies; provided the foregoing covenant is limited to use by such Customer (i) of such specific copies that are authorized by Novell in consideration for such Revenue, and (ii) within the scope authorized by Novell in consideration for such Revenue.
- ^ "Definitions". Microsoft. November 2, 2006. Archived from the original on November 4, 2012. Retrieved July 5, 2009.
- ^ Steinman, Justin (November 7, 2006). "Novell Answers Questions from the Community". Archived from the original on July 16, 2013. Retrieved July 5, 2009.
We maintain that Mono does not infringe any Microsoft patents.
- ^ "Covenant to Downstream Recipients of Moonlight - Microsoft & Novell Interoperability Collaboration". Microsoft. September 28, 2007. Archived from the original on September 23, 2010. Retrieved March 8, 2008.
"Downstream Recipient" means an entity or individual that uses for its intended purpose a Moonlight Implementation obtained directly from Novell or through an Intermediate Recipient... Microsoft reserves the right to update (including discontinue) the foregoing covenant... "Moonlight Implementation" means only those specific portions of Moonlight 1.0 or Moonlight 1.1 that run only as a plug-in to a browser on a Personal Computer and are not licensed under GPLv3 or a Similar License.
- ^ a b "The RyuJIT transition is complete!". microsoft.com. June 19, 2018. Archived from the original on July 19, 2019. Retrieved July 20, 2021.
- ^ "Managed Execution Process". microsoft.com. Archived from the original on December 23, 2017. Retrieved July 20, 2021.
- ^ "coreclr/src/jit/". github.com. Archived from the original on January 9, 2019. Retrieved July 20, 2021.
- ^ "C# Guide". Microsoft Learn. Archived from the original on August 13, 2022. Retrieved July 28, 2017.
- ^ "5.0.8". microsoft.com. Archived from the original on April 23, 2020. Retrieved July 20, 2021.
- ^ "Mitigation: New 64-bit JIT Compiler". microsoft.com. Archived from the original on April 5, 2018. Retrieved July 20, 2021.
- ^ Etcheverry, Ignacio (October 21, 2017). "Introducing C# in Godot". Godot Engine. Archived from the original on October 26, 2018. Retrieved October 26, 2018.
Sources
- Albahari, Joseph (2022). C# 10 in a Nutshell (First ed.). O'Reilly. ISBN 978-1-098-12195-2.
- Archer, Tom (2001). "Part 2, Chapter 4: The Type System". Inside C#. Redmond, Washington: Microsoft Press. ISBN 0-7356-1288-9.
- Novák, István; Velvart, Andras; Granicz, Adam; Balássy, György; Hajdrik, Attila; Sellers, Mitchel; Hillar, Gastón C.; Molnár, Ágnes; Kanjilal, Joydip (2010). Visual Studio 2010 and .NET 4 Six-in-One. Wrox Press. ISBN 978-0470499481.
- Skeet, Jon (2019). C# in Depth (Fourth ed.). Manning. ISBN 978-1617294532.
Further reading
- Drayton, Peter; Albahari, Ben; Neward, Ted (2002). C# Language Pocket Reference. O'Reilly. ISBN 0-596-00429-X.
- Petzold, Charles (2002). Programming Microsoft Windows with C#. Microsoft Press. ISBN 0-7356-1370-2.
External links
- C Sharp programming language family
- 2000 software
- American inventions
- Programming languages
- High-level programming languages
- .NET programming languages
- Class-based programming languages
- Ecma standards
- Functional languages
- IEC standards
- ISO standards
- Microsoft programming languages
- Multi-paradigm programming languages
- Programming languages created in 2000
- Programming languages with an ISO standard
- Statically typed programming languages
- Compiled programming languages