Pressing F5 to compile and run the above C # program will produce the following results:
Using keyword in C #
The first command in any C # program is:
using System ;
The using keyword is used to include namespaces in the program. A C # program can include many using statements.
Keyword class in C #
The keyword class is used to declare a class in C #.
Comments in C #
The comment is used to initialize the code. Compiler ignores comments. Multi-line comments in C # programs start with / * and end with * / as follows:
/* dong nay minh hoa comment nhieu dong trong C#. Cu phap co ban C# Ngon ngu lap trinh C# */
Single-line comments are indicated by the symbol '//'. For example:
// vi du comment don dong trong C#
Turning members in C #
Variables are attributes or data members of a class, used to store data. In the previous program, Rectangle class has two member variables which are length and width.
Member functions in C #
A function is a collection of commands that perform a specific task. The member functions of a class are declared inside that class. Rectangle class contains 3 member functions: AcceptDetails, GetArea and Display.
Explain a Class in C #
In the above program, the ExecuteRectangle class contains the Main () method and initializes the Rectangle class.
Identifier in C #
An identifier is a name used to identify a class, variable, function or any self-defined item (user-defined).
A name must start with a letter that can be followed by a sequence of letters, numbers (0-9) or underscore (_). The first character of an identifier cannot be a digit.
It must not contain any spaces or characters like? - +! @ #% ^ & * () [] {}. ; : "'/ and. However, underscores can be used.
It should not be a keyword in C #.
Keywords in C #
Keywords are predefined reserved words (Reserved Keyword) for C # compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you can set the @ character before them.
In C #, some identifiers that have special meanings in the context of the code, such as get and set, are called contextual keywords.
The following table lists reserved keywords and contextual keywords in C #:
Reserved Keywordabstract as base bool break byte case checked catch char class const continue decimal default delegate due to double else the event enum explicit extern false finally fixed float for foreach goto if implicit in (Generic modifier) int internal interface (lock) không có một tên của đường dẫn không thể xác định là một tên tập tin, không phải là một số thứ tự đối tượng, không rõ đã kết thúc với bộ đệm chung (tùy chọn chung đã xác định) public readonly ref đã chuyển lại sealed Sbyte sizeof static stack string struct chuyển đổi này không thể thực hiện typeof uint ulong unchecked unsafe ushort using virtual void volatile while Contextual keyword inh global group vào Join một let (không hợp lệ) phần (kiểu) phầnFollow tutorialspoint
Previous article: C # program structure
Next lesson: Data type in C #