- 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.
- 嵌入式軟件系統測試:基于形式化方法的自動化測試解決方案
- Linux C/C++服務器開發實踐
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- 算法訓練營:入門篇(全彩版)
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- Web Application Development with R Using Shiny(Second Edition)
- Bootstrap 4:Responsive Web Design
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- SharePoint Development with the SharePoint Framework
- Learning ArcGIS for Desktop
- Quantum Computing and Blockchain in Business
- BeagleBone Robotic Projects(Second Edition)
- 零代碼實戰:企業級應用搭建與案例詳解
- SwiftUI極簡開發
- Scratch從入門到精通