Get the App
SLTechnology News&Howtos  ›  Development  › 

Case Analysis of basic Grammar of C #

Shulou Source: shulou.com Published: 2022-06-01 00:10:08 10月04日 Update

Most people do not understand the knowledge points of this "C# basic Grammar case Analysis" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "C# basic Grammar case Analysis" article.

one。 Basic grammar

1.C# is case-sensitive, so myVar and MyVar are two different variables.

two。 Every C# executable (such as console applications, Windows applications, and Windows services) must have an entry point-Main () (M uppercase)

Public static void Main () {/ / do something}

This method is called when the program starts. This method either returns no value (void) or returns an integer (int)

two。 Variable

1. The compiler does not allow uninitialized variables to be used in expressions. If the variables are fields in a class or structure, if they are not initialized, when they are created, the default value is 0.

two。 Type inference

Type inference (type inference) uses the var keyword. The compiler can "infer" the type of a variable based on its initialization value. Var somenum = 0; even if somenum is never declared as int, the compiler can determine that as long as somenum is within its scope, it is an int. After the variable is declared and the type is inferred, the variable type cannot be changed. Once the type of the variable is determined, the strongly typed rules followed by other variable types are followed.

3. Scope of variables

The scope of a variable is the area of code that accesses the variable. As long as the scope of the variable is different parts of the program, there will be no problem.

(1)。 Scope conflict of local variables

Public static int Main () {int j = 20; for (int item0)

Tags: Variables compilers types names methods codes constants programs compilers instructions spaces functions preprocessing syntax two characters strings actual instances Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Apple macOS Xiaomi