Table of Contents
C # Programming Language: Basic C # Syntax is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
C # is an object-oriented programming language. In an object-oriented programming method, a program consists of diverse objects that interact with each other by action methods. Actions that an object can receive are called methods. Objects of the same type are considered as having the same type or, as if they were in the same class.
For instance,, consider the Rectangle object. It has attributes like length and width. Depends on the design above. It may need ways to grant these attribute values, calculate area and show details.
You follow the example after deploying a Rectangle class and the basic C # syntax of this program. To clearly illustrate the object-oriented nature of C #, I will create two classes in two files separately.
Rectangle : contains the main properties and methods:
using System ; namespace QTMsharp { class Rectangle { // các bi?n thành viên double length ; double width ; // ph??ng th?c public void Acceptdetails () { length = 4.5 ; width = 3.5 ; } // ph??ng th?c public double GetArea () { return length * width ; } // ph??ng th?c public void Display () { Console . WriteLine ( "Chieu dai: {0}" , length ); Console . WriteLine ( "Chieu rong: {0}" , width ); Console . WriteLine ( "Dien tich: {0}" , GetArea ()); } } }
Class ExecuteRectangle : is a class containing main () method to conduct manipulation on Rectangle object of Rectangle class. Come here, maybe you do not understand anything, but it's okay because this is just a chapter to help you get acquainted with C #.
dùng System;
QTMsharp namespace
{
class ExecuteRectangle
{
static void Main (string [] args)
{
Console.WriteLine ("Full version in C #");
Console.WriteLine ("--------------------------------------------- ----- n ");
// tao doi tuong Rectangle
Rectangle r = new Rectangle ();
// Call the current version
r.Acceptdetails ();
r.Display ();
Console.ReadLine ();
Console.ReadKey ();
}
}
}
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 helps include namespaces in the program. A C # program can include many using statements.
Keyword class in C #
The keyword class helps declare a class in C #.
Comments in C #
The comment helps 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 instance,:
// 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 #:
(method) remove select setNext lesson: Data type in C #
FAQ
What is C # Programming Language: Basic C # Syntax?
C # is an object-oriented programming language.
Why is C # Programming Language: Basic C # Syntax important?
A clear understanding of C # Programming Language: Basic C # Syntax helps you make informed decisions, avoid common mistakes, and use the relevant tools or techniques more effectively.
How should beginners approach C # Programming Language: Basic C # Syntax?
Start with the fundamental concepts, follow the examples step by step, and test each change in a safe environment before applying it to important systems or data.
Reader Comments 0
Sign in with email or Google to join the discussion.