- Learn C# in 7 days
- Gaurav Aroraa
- 303字
- 2021-07-08 09:51:27
Understanding statements
In C#, you can evaluate different kinds of expression that would or would not generate the results. Whenever you say something like what would happen if result >0, in that case, we are stating something. This can be a decision-making statement, result-making statement, assignment statement, or any other activity statement. On the other hand, loops are a code block that repeatedly executes a couple of statements.
In this section, we will discuss statements and loops in detail.
A statement should perform some action before returning a result. In other words, if you are writing a statement, that statement should say something. To do that, it has to execute some inbuilt or custom operations. Statements can depend upon a decision or can be a part of the result of any existing statement. The official page (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/statements) defines statement as:
Take a look at the following code snippet, which shows different statements:
private static void StatementExample() { WriteLine("Statement example:"); int singleLineStatement; //declarative statement WriteLine("'intsingleLineStatement;' is a declarative statment."); singleLineStatement = 125; //assignment statement WriteLine("'singleLineStatement = 125;' is an assignmnet statement."); WriteLine($"{nameof(singleLineStatement)} = {singleLineStatement}"); var persons = newList<Person> {
newAuthor {Name = "Gaurav Aroraa" } }; //declarative and assignmnet statement WriteLine("'var persons = new List<Person>();' is a declarative and assignmnet statement.");
//block statement foreach (var person in persons) { WriteLine("'foreach (var person in persons){}' is a block statement."); WriteLine($"Name:{person.Name}"); } }
In the preceding code, we used three type statements: declarative, assignment, and block statements. The code produces the following result:

According to the official page (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/statements), C# statements can be broadly divided into the following categories.
- ClickHouse性能之巔:從架構(gòu)設(shè)計解讀性能之謎
- Raspberry Pi Networking Cookbook(Second Edition)
- Learning RxJava
- Vue.js 3.x從入門到精通(視頻教學(xué)版)
- Network Automation Cookbook
- WSO2 Developer’s Guide
- Oracle Database 12c Security Cookbook
- 0 bug:C/C++商用工程之道
- Learning iOS Security
- 3D Printing Designs:Octopus Pencil Holder
- Java設(shè)計模式深入研究
- Mastering Object:Oriented Python(Second Edition)
- Beginning C# 7 Hands-On:The Core Language
- 高性能MVVM框架的設(shè)計與實現(xiàn):San
- Java Web應(yīng)用開發(fā)