官术网_书友最值得收藏!

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:

A statement can consist of a single line of code that ends in a semicolon, or a series of single-line statements in a block. A statement block is enclosed in {} brackets and can contain nested blocks.

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&lt;Person&gt;();' 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.

主站蜘蛛池模板: 玉环县| 融水| 张掖市| 隆尧县| 东宁县| 乾安县| 礼泉县| 左云县| 淮北市| 和林格尔县| 平遥县| 呼伦贝尔市| 横峰县| 南雄市| 沂南县| 临澧县| 瑞安市| 金沙县| 黄冈市| 濉溪县| 兴业县| 定襄县| 岫岩| 炉霍县| 盱眙县| 通榆县| 铜梁县| 旬邑县| 府谷县| 攀枝花市| 奈曼旗| 休宁县| 平塘县| 礼泉县| 宜章县| 米泉市| 临猗县| 犍为县| 平陆县| 布尔津县| 通河县|