3.1. C # Basics-C # 's Hello World (2)

Source: Internet
Author: User

In the previous article, you followed me by writing a HelloWorld, in this article, we'll talk about small concepts in some C # programs

1. C # Program Structure

A C # program mainly includes the following sections:

    • namespace declaration (Namespace declaration)
    • A class
    • Class method
    • Class Property
    • A main (Master) method
    • Statements (statements) & Expressions (Expressions)
    • Comments

Let's add the last piece of code.

1 usingSystem;2 3 namespaceHelloWorld4 {5     class Program6     {7         Static voidMain (string[] args)8         {9Console.Write ("HelloWorld");Ten Console.read (); One         } A     } -}

The 1th line of the program using System; -The Using keyword is used to include the System namespace in your program. A program typically has multiple using statements

The next line of namespace Helloworld-namespace keyword is used to declare namespaces, and there are multiple classes in a namespace. In this code, it represents a namespace that is HelloWorld

The next line of class Program-class keywords is used to declare a class that contains the data and method declarations used by the program. Class generally contains multiple methods. Method defines the behavior of the class. Here, the program class has only one Main method.

The next line defines the Main method, which is the entry point for all C # programs. The Main method describes what actions the class will do when it executes.

Comments are used to interpret the code. The compiler ignores the entry for the comment. In a C # program, a multiline comment starts with/* and terminates as a character, as follows:

/**/

a single-line comment is denoted by a '//' symbol. For example:

//


2. What is an identifier

Identifiers are used to identify a class, variable, function, or any other user-defined item. In C #, the naming of a class must follow the following basic rules:

    • Identifiers must begin with a letter, underscore, or @, followed by a series of letters, Numbers (0-9), underscores (_), and @.
    • The first character in an identifier cannot be a number.
    • The identifier must not contain any embedded spaces or symbols, such as? - +! #% ^ & * () [] {}. ; : " ‘ / \。
    • The identifier cannot be a C # keyword. Unless they have an @ prefix. For example, @if is a valid identifier, but if is not, because if is a keyword.
    • Identifiers must be case sensitive. Uppercase and lowercase letters are considered to be different letters.
    • cannot be the same as the class library name for C #.

3. What is C # keyword

The keyword is a predefined reserved word for the C # compiler. These keywords cannot be used as identifiers, but if you want to use these keywords as identifiers, you can prefix them with the @ character before the keyword.
In C #, some identifiers have special meanings in the context of the code, such as Get and set, which are called contextual keywords (contextual keywords).
The following table lists the reserved keywords (Reserved Keywords) and the contextual keywords (contextual Keywords) in C #:

Reserved keywords

Context keywords

See: https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/

3.1. C # Basics-C # 's Hello World (2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.