ស៊ីទ្រុងជ្រូក៖ ភាពខុសគ្នារវាងកំណែនានា

ខ្លឹមសារដែលបានលុបចោល ខ្លឹមសារដែលបានសរសេរបន្ថែម
remove unused category
Bot: Replace deprecated <source> tag and "enclose" parameter [https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2020-April/002284.html]; cosmetic changes
បន្ទាត់ទី៦៖
{{Infobox programming language
|name = ស៊ីឝាប (C#)
|logo = [[Fileឯកសារ:C Sharp wordmark.svg|150px]]
|year = ២០០០, ១៦ ឆ្នាំកន្លងទៅ
|designer = [[ម៉ៃក្រូសប]]
បន្ទាត់ទី៥២៖
* 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.
 
== ឈ្មោះ ==
[[Imageឯកសារ:C Sharp wordmark.svg|thumbរូបភាពតូច|100px|rightស្តាំ|[[C♯ (musical note)|C-sharp musical note]] (left)]]
The name "C sharp" was inspired by musical notation where a [[Sharp (music)|sharp]] 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
បន្ទាត់ទី៩៩៖
}}</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), [[Cocoa Sharp|Cocoa#]] (a wrapper for [[Cocoa (API)|Cocoa]]) and [[Qt Sharp|Qt#]] (a .NET language binding for the [[Qt (toolkit)|Qt toolkit]]).
 
== ប្រវត្តិ ==
During the development of the .NET Framework, the [[Base Class Library|class libraries]] were originally written using a [[managed code]] compiler system called ''Simple Managed C'' (SMC).<ref>{{cite web
|url= http://blogs.msdn.com/jasonz/archive/2007/11/23/couple-of-historical-facts.aspx
បន្ទាត់ទី២៩១៖
</center>
 
== Syntax ==
{{Main|C Sharp syntax}}
{{See also|Syntax (programming languages)}}
បន្ទាត់ទី៣០៣៖
<!-- I tried to make this overview easily readable for people other than computer scientists. Sorry that it was nowhere near inclusive enough, but I lacked adequate time to finish it.-->
 
=== Distinguishing features ===
:''Note: The following description is based on the language standard and other documents listed in the "[[#External links|External links]]" section.''
 
បន្ទាត់ទី៣៣៥៖
* Though primarily an imperative language, since C# 3.0 it supports functional programming techniques through [[first-class function]] objects and [[Anonymous function|lambda expressions]].
 
== ប្រព័ន្ធប្រភេទសាមញ្ញ ==
C# has a ''unified type system''. This unified type system is called [[Common Type System]] (CTS).<ref name="insidecsharpp2ch4">{{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}}</ref>
 
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.
 
=== ចំណាត់ថ្នាក់ក្រុមប្រភេទទិន្នន័យ ===
CTS separates data types into two categories:<ref name="insidecsharpp2ch4" />
 
បន្ទាត់ទី៣៥២៖
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.<ref name="insidecsharpp2ch4" /> Boxing in C# is implicit.
 
បន្ទាត់ទី៣៥៨៖
 
Example:
<syntaxhighlight lang="CSharp">
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
បន្ទាត់ទី៣៦៤៖
</syntaxhighlight>
 
=== Generics ===
[[Generic programming|Generics]] were added to version 2.0 of the C# language. Generics use type parameters, which make it possible to design classes and methods that do not specify the type used until the class or method is instantiated. The main advantage is that one can use generic type parameters to create classes and methods that can be used without incurring the cost of runtime casts or boxing operations, as shown here:<ref>{{cite web| title = Generics (C# Programming Guide)| url = http://msdn.microsoft.com/en-us/library/512aeb7t.aspx| publisher = Microsoft| accessdate = August 7, 2011}}</ref>
 
<syntaxhighlight lang="CSharp">
// Declare the generic class.
 
បន្ទាត់ទី៣៩២៖
</syntaxhighlight>
 
== Preprocessor ==
C# features "preprocessor directives"<ref>{{cite web
| url = http://msdn.microsoft.com/en-us/library/ed8yd1ha.aspx
បន្ទាត់ទី៤០១៖
}}</ref> (though it does not have an actual preprocessor) based on the [[C preprocessor]] that allow programmers to define [[Symbol (programming)|symbols]], but not macros. Conditionals such as {{C sharp|#if}}, {{C sharp|#endif}}, and {{C sharp|#else}} are also provided. Directives such as {{C sharp|#region}} give hints to editors for [[code folding]].
 
<syntaxhighlight lang="CSharp">
public class Foo
{
បន្ទាត់ទី៤២១៖
C# utilizes a double slash ({{C sharp|//}}) to indicate the rest of the line is a [[Comment (computer programming)|comment]]. This is inherited from [[C++]].
 
<syntaxhighlight lang="CSharp">
public class Foo
{
បន្ទាត់ទី៤៣១៖
Multi-line comments can start with slash-asterisk ({{C sharp|/*}}) and end asterisk-slash ({{C sharp|*/}}). This is inherited from standard [[C (programming language)|C]].
 
<syntaxhighlight lang="CSharp">
public class Foo
{
បន្ទាត់ទី៤៤៦៖
Single-line documentation comments, such as those commonly found in [[Microsoft Visual Studio|Visual Studio]] generated code, are indicated on a line beginning with {{C sharp|///}}.
 
<syntaxhighlight lang="CSharp">
public class Foo
{
បន្ទាត់ទី៤៧២៖
}}</ref>
 
<syntaxhighlight lang="CSharp">
public class Foo
{
បន្ទាត់ទី៤៨៦៖
This code block:
 
<syntaxhighlight lang="CSharp">
/**
* <summary>
បន្ទាត់ទី៤៩៤៖
produces a different XML comment from this code block:<ref name="Delimiters for Documentation Tags"/>
 
<syntaxhighlight lang="CSharp">
/**
* <summary>
បន្ទាត់ទី៥០៨៖
The following is a very simple C# program, a version of the classic "[[Hello world]]" example:
 
<syntaxhighlight lang="CSharp">
using System;
 
បន្ទាត់ទី៥២៦៖
Each line has a purpose:
 
<syntaxhighlight lang="CSharp">
using System;
</syntaxhighlight>
បន្ទាត់ទី៥៣២៖
The above line of code tells the compiler to use <code>System</code> as a candidate prefix for types used in the source code. In this case, when the compiler sees use of the <code>Console</code> type later in the source code, it tries to find a type named <code>Console</code>, first in the current assembly, followed by all referenced assemblies. In this case the compiler fails to find such a type, since the name of the type is actually <code>System.Console</code>. The compiler then attempts to find a type named <code>System.Console</code> by using the <code>System</code> prefix from the {{C sharp|using}} statement, and this time it succeeds. The {{C sharp|using}} statement allows the programmer to state all candidate prefixes to use during compilation instead of always using full type names.
 
<syntaxhighlight lang="CSharp">
class Program
</syntaxhighlight>
បន្ទាត់ទី៥៣៨៖
Above is a [[Class (computer science)|class]] definition. Everything between the following pair of braces describes {{C sharp|Program}}.
 
<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. (Note: {{C sharp|Main}} may also be called from elsewhere, like any other method, e.g. from another method of {{C sharp|Program}}.) The {{C sharp|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, 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]].
 
<syntaxhighlight lang="CSharp">
Console.WriteLine("Hello world!");
</syntaxhighlight>
បន្ទាត់ទី៥៥២៖
A [[GUI]] example:
 
<syntaxhighlight lang="CSharp">
using System.Windows.Forms;
 
បន្ទាត់ទី៦២៥៖
| accessdate = 2009-078-03}}</ref> would not prevent Microsoft from harming free implementations of C#, because many specific Windows libraries included with .NET or [[Mono (software)|Mono]] were not covered by this promise.
 
== Implementations ==
The reference C# compiler is [[Microsoft Visual C Sharp|Microsoft Visual C#]], which is closed-source.
 
បន្ទាត់ទី៦៣៣៖
* Microsoft's Rotor project (currently called [[Shared Source Common Language Infrastructure]]) (licensed for educational and research use only) provides a [[shared source]] implementation of the CLR runtime and a C# compiler, and a subset of the required [[Common Language Infrastructure]] framework libraries in the ECMA specification (up to C# 2.0, and supported on Windows XP only).
 
== សូមមើលផងដែរ ==
{{Portal|Computer programming}}
{{Multicol}}
បន្ទាត់ទី៦៥៥៖
{{Clear}}
 
== កំណត់ ==
{{Reflist|group="note"}}
 
== ឯកសារយោង ==
{{Reflist|30em|refs=
<ref name="dynamic">{{cite web
បន្ទាត់ទី៧០០៖
}}
 
== អំណានបន្ថែម ==
* {{cite book | title = C# Language Pocket Reference| 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}}
 
== តំណភ្ជាប់ក្រៅ ==
{{Wikibooks|C Sharp Programming}}
* [http://go.microsoft.com/fwlink/?LinkId=199552 C# Language Specification (from MSDN)]