Posts

Showing posts from November, 2022

Conditional Statement in C#

  Condition Statement: A statement that can be executed based on a condition is known as a “Conditional Statement”.   The statement is often a block of code.   The following are the 2 types: Conditional Branching. Conditional Looping.         Conditional Branching: This statement allows you to branch your code depending on whether or not a certain condition is met.   In C# are the following conditional branching statements:   1.    if statement.   2.    if-else statement.   3.    if-else-if ladder statement.   4.    Nested if statement.   5.    switch case statement.   Here if, else and switch are pre-defined keywords.         1.   if Statement: If statement checks the given Boolean condition. If the Boolean condition evaluates to be true then the block of code/statements will...

Enums in C#

  Enum: v An enum is a collection of named integer constants.   v To create an enum, use the enum keyword.   v Enum is short for "enumerations", which means "specifically listed".   v By default, the associated constant values of enum members are of type int and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.   v Enums are not for end-users, they are meant for developers.   v Enum values are fixed. Enum can be displayed as a string and processed as an integer.   v An explicit cast is required to convert from enum type to an integral type.   v Enums are value types and are created on the stack and not on the heap.   v Enum constants has default values which starts from 0 and incremented to one by one. But we can change the default value.   v We can only assign integral values to the enum names. We should not assign strings as values. Enum in C# can be declared wit...

Structure in C#

  Structure:   v In C#, Structure are used to hold data of various data types into a single variable.   v The struct keyword is used for creating a structure.   v Structure is a value type data type.   v Structures can have methods, fields, indexers, properties, operator, methods, and events etc.   v Structures cannot inherit other structures or classes.   v Structures cannot be used as a base for other structures or classes.   v A structure can implement interfaces.   v Structure members cannot be specified as abstract, sealed virtual, or protected.   v A structure can be instantiated with or without using a new keyword.   v If the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized.       Structure Declaration & Object Creation: The keyword struct can be used to declare a structure. T...