Posts

Showing posts from 2023

Record types in C#.NET

What are Record Types in C#? Records in C# 9 provide a way to create immutable value types. The  record  keyword defines a record type like enums, structs, and classes. However, these other types of constructs, record types are designed to be immutable by default. When you define a record type with properties and methods, the compiler will ensure those properties can never change after they are created. Anatomy of Record Types in C# In C# 9, records are a new type that can replace classes and structs. Record structs are introduced in C# 10, allowing you to define records as value types. The difference between records and classes is that records utilize value-based equality. Records of the same type with similar specifications and similar values in all fields are equal. In C# 9, a record type is a lightweight, immutable data type (or lightweight class) with primarily read-only properties. A record type is thread-safe, and because it is immutable, you cannot change it after it i...

Jump Statements in C#.Net

  Jump Statements in C# In C#, Jump statements are used to transfer control from one point to another point in the program due to some specified code while executing the program.   There are below keywords in the Jump Statements: ·        goto ·        break ·        continue ·        return ·        throw   goto : This statement is used to transfer control to the labeled statement in the program. The label is the valid identifier and placed just before the statement from where the control is transferred. break : The break statement is used to terminate the loop or statement in which it present. After that, the control will pass to the statements that present after the break tatement, if available. continue : This statement is used to skip over the execution part of the loop on a certain condition. Af...

Conditional Looping Statements in C#.NET

  Conditional Looping  Statements C# provides 4 loops that allow you to execute a block of code repeatedly until a certain condition is met; They are: ·        for ·        while ·        do while ·        foreach   For Loop For Loop is a loop in programming languages like C# that repeats a block of statements until a condition provided is satisfied. Unlike other less structured loops like while and do. While, this loop contains initialization, condition and increment/decrement before the loop statement. syntax : for (initialization; condition; increment/decrement) {     statements; }             Example The below statement will execute 4 times repeatedly until the specified condition gets fail.          ...

Conditional Statements in C#

  Conditional Statements A statement that can be executed based on a condition is known as a “Conditional Statement”. The statement is often a block of code.   There 3 type of conditional statements ·                  Conditional Branching ·                  Conditional Loop ·                  Jump Statement s   Conditional Branching: C# Conditional Branching primarily focuses on If and Switch statements, the main mechanisms for executing or branching to different code depending on whether a condition is true or false In C# are the following 2 conditional branching statements 1. if statement 2. Switch statement   if Statement The if statement allows you to test whether or not a specific condition is met. Syntax If(<Condition>)   <statements>;...