C Sharp Programming/Syntax

C# syntax looks quite similar to the syntax of Java because both inherit much of their syntax from C and C++. The object-oriented nature of C# requires the high-level structure of a C# program to be defined in terms of classes, whose detailed behaviors are defined by their statements.

Statements
The basic unit of execution in a C# program is the statement. A statement can declare a variable, define an expression, perform a simple action by calling a method, control the flow of execution of other statements, create an object, or assign a value to a variable, property, or field. Statements are usually terminated by a semicolon.

Statements can be grouped into comma-separated statement lists or brace-enclosed statement blocks.

Examples:

Statement blocks
A series of statements surrounded by curly braces form a block of code. Among other purposes, code blocks serve to limit scope, or the range in which a variable can be used. A variable is only accessible in the block in which it is defined. Code blocks can be nested and often appear as the bodies of methods.

Comments
Comments allow inline documentation of source code. The C# compiler ignores comments. These styles of comments are allowed in C#:
 * Single-line comments: The character sequence marks the following text as a single-line comment. Single-line comments, as one would expect, end at the first end-of-line following the  comment marker.
 * Multiple-line comments: Comments can span multiple lines by using the multiple-line comment style. Such comments start with and end with . The text between those multi-line comment markers is the comment.


 * XML Documentation-line comments: These comments are used to generate XML documentation. Single-line and multiple-line styles can be used. The single-line style, where each line of the comment begins with, is more common than the multiple-line style delimited by and.

Case sensitivity
C# is case-sensitive, including its variable and method names.

The variables and  of type  below are distinct because C# is case-sensitive: For example, C# defines a class to handle most operations with the console window. Writing the following code would result in a compiler error unless an object named had been previously defined.

The following corrected code compiles as expected because it uses the correct case:

C 샤프 프로그래밍/문법