Posts

Showing posts with the label C# Free Course

Functions in C#

Functions in C# In C#, functions are blocks of code that perform specific tasks. They are essential for breaking down complex programs into smaller, more manageable units. This modular approach improves code readability, reusability, and maintainability. Basic Structure of a Function: [access_modifier] return_type function_name(parameter_list) {     // Function body     // ...     return value; // Optional, if return_type is not void } Key Components:  * Access Modifier:    * public: Accessible from anywhere.    * private: Accessible only within the same class.    * protected: Accessible within the same class and its derived classes.    * internal: Accessible within the same assembly.  * Return Type:    * Specifies the data type of the value returned by the function.    * void: Indicates that the function doesn't return any value.  * Function Name:    * A unique identifier ...

C# Comparison Operators

C# Comparison Operators Comparison operators in C# are used to compare values and return a boolean result (true or false). They are essential for making decisions and controlling the flow of your program. Here's a table of the common comparison operators: | Operator | Description | Example | |---|---|---| | == | Equal to | if (x == y) | | != | Not equal to | if (x != y) | | > | Greater than | if (x > y) | | < | Less than | if (x < y) | | >= | Greater than or equal to | if (x >= y) | | <= | Less than or equal to | if (x <= y) | Example: int x = 10; int y = 5; // Using comparison operators bool isEqual = x == y; // False bool isGreater = x > y; // True bool isLessOrEqual = x <= y; // False // Using comparison operators in an if statement if (x > y) {     Console.WriteLine("x is greater than y"); } else {     Console.WriteLine("x is not greater than y"); } Important Notes:  * Null Comparison: When comparing reference types (like str...