“This is the 22nd day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

Welcome friends to search “Andy Hui” on wechat to pay attention to a wave!

Write some thoughts of the programmer, hope it will help you.

remarks

The next few articles will give you a brief overview of the common syntax in C# that we use in coding.

Today we introduce statements in C#.

Generally trained program apes are the first language we learn basic C language, C language in the beginning of the introduction of statements. The statements described in C# are basically the same as in C (which is why I recommend starting with C# or JAVA and learning C first. Everything.

statements

Statements are source code instructions that describe a type or make a program perform an action. It is divided into declaration statement, embedded statement and label statement.

If you go into detail there are empty statements, block statements, simple statements and so on.

A simple statement consists of an expression followed by a semicolon, and a block is a sequence of statements enclosed in braces. Blocks can also contain declarations, nesting, tags, etc.

Int age = 27; String name = "ahui" // block {int ageTwo = 27; ageTwo if (true) { ; // empty statement}}Copy the code

A block counts syntactically as a single embedded statement. Blocks can be used anywhere syntactically you need an embedded statement. The same goes for null statements.

Expression statement

You can create a statement from an expression by placing a statement terminator (semicolon) after the expression.

  x=10;
Copy the code

The above code consists of an assignment expression followed by a semicolon. It assigns the value to the right of the operator to the memory location referenced by the variable x. After setting the value of x, the expression returns the new value of x.

Control flow statement

Conditional execution executes or skips a code snippet based on a condition.

if; if... else; switch;Copy the code

A loop statement executes a piece of code repeatedly

do;
while;
for;
foreach;
Copy the code

A jump statement changes the flow of control from one snippet to a specified statement in another snippet

break;
continue;
return;
goto;
throw;
Copy the code

Conditional execution and loop constructs (except foreach) require a test expression or condition to determine where the program should continue execution.

Here is a brief description of jump statements.

These jump statements can be used in for, foreach, while, or do loops.

  int x = 27;
  while (true)
  {
      x++;
      if (x > 100)
          break;
  }
Copy the code

In the case of throwing for exception handling, throw is used to throw an exception up the module level.

try { int x = 27; while (true) { x++; if (x > 100) break; }} catch (Exception ex) {throw new Exception(" +ex.Message "); }Copy the code

So that’s the basics for today, and I’ll see you tomorrow.

remarks

Life is short. I don’t want to go for what I can’t see. I want to catch what I can see.

Original is not easy, give a attention.

I am Hui, thank you for reading, if it is helpful to you, please like, forwarding thank you.