How the idea came to me: When I first started programming back in my late twenties, I remember feeling both excited and overwhelmed by the sheer possibilities the world of code could offer. I’d just gotten my first taste of C#, and after mastering “Hello World!” I knew I needed to create something interactive and…
Category: Uncategorized
The Essential C#/.NET Handbook # 103 – 110
103. recursion Recursion in C# refers to a method or function calling itself. It is often used to solve problems that can be broken down into smaller, repetitive subproblems, such as traversing tree structures, implementing algorithms like factorial, Fibonacci sequences, and certain sorting algorithms (e.g., quicksort and mergesort). Recursive functions typically include a…
The Essential C#/.NET Handbook # 94 – 102
94. partial methods Partial methods allow a method to be declared but not necessarily implemented in a partial class or struct. If an implementation is provided, it gets compiled; if not, the method is completely removed at compile time. This provides a mechanism for extensibility without incurring runtime overhead. Example: Declaring a Partial…
The Essential C#/.NET Handbook # 86 – 93
86. checked The checked keyword in C# enforces overflow checking in arithmetic operations and conversions. By default, integer operations in C# do not throw exceptions when an overflow occurs; they wrap around instead, meaning values “roll over” when they exceed the type’s capacity. The checked keyword prevents this behavior by explicitly throwing an…
The Essential C#/.NET Handbook # 80 -85
80. implicit operator An implicit operator in C# defines automatic type conversions between user-defined types and other types without requiring an explicit cast. It prevents unnecessary casting syntax while ensuring type safety. To define an implicit conversion, use the implicit keyword inside a class: public class Temperature { public double Celsius {…
The Essential C#/.NET Handbook # 73 – 79
73. where constraints Where constraints in C# impose rules on generic type parameters to ensure that only compatible types are used in generic classes or methods. They enhance type safety by restricting which types can be substituted for a given type parameter. The where keyword is used to define constraints, such as: where…
The Essential C#/.NET Handbook # 66 – 72
66. lambda expression What is a Lambda Expression? A lambda expression is a concise, anonymous function that can be assigned to a delegate or used in LINQ queries. It uses the => syntax. Basic Example Func<int, int> Square = x => x * x; Console.WriteLine(Square(5)); // Output: 25 Here, x => x *…
The Essential C#/.NET Handbook # 61 – 65
61. params keyword The params keyword lets a method accept a variable number of arguments, which are treated as an array. Example: void PrintNumbers(params int[] numbers) { foreach (var num in numbers) Console.WriteLine(num); } PrintNumbers(1, 2, 3, 4); // Treated as an int[] Key Features: Allows passing multiple arguments without manually…
The Essential C#/.NET Handbook # 48 – 60
48. protected A protected member is accessible within the same class and derived classes but not from outside classes. Example: class Parent { protected int data = 42; } class Child : Parent { public void ShowData() { Console.WriteLine(data); // Allowed } } This is useful for inheritance,…
The Essential C#/.NET Handbook # 34 – 47
34. enum An enum (enumeration) is a named set of constants, making code more readable and maintainable by replacing magic numbers with meaningful names. Example: enum DayOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } DayOfWeek today = DayOfWeek.Monday; Enums improve code clarity and reduce errors by restricting values to predefined options….