December 2026
Every post published in December 2026, newest first. Pick a day to jump straight to it.
- Posts
- 132
- Topics
- 48
- Reading time
- 13 h
- Active days
- 2
Posts 121–132 of 132 · December 1, 2026
Page 5 of 5
Tuesday, December 1, 2026
12 of 97 posts
How to Pass null to an Overloaded Method in C#
Passing a bare null to an overloaded method in C# fails with error CS0121 when more than one overload can take null. A small example with Show(string?) and Show(int?) picks each overload with a cast: (string?)null printed Show(string?) got null. With real output and what happens with default, (int)null and (string)null.
7 min readHow to Mix int and decimal Values in One Calculation in C#
Mix an int with a decimal or a double in one C# calculation, and the int converts by itself. A small example multiplies 38 hours by 15.75m to 598.50 as a decimal and divides 90 by 60.0 to 1.5 as a double, with real output, the CS0266 and CS0019 errors, and why 38 / 4 gave 9.
7 min readHow to Use a Tuple with Named Elements in C#
A tuple with named elements in C# holds a few values together and lets you read each one by name, such as result.Quotient, without declaring a class. A small example returns 17 divided by 5 as a quotient of 3 and a remainder of 2 from one method, prints (3, 2), and shows the errors and the silent swap that tuple names can cause.
7 min readHow to Get the First Item or a Default with LINQ FirstOrDefault in C#
LINQ's FirstOrDefault in C# returns the first item that passes a test, or a default value when none does, which is null for a string, 0 for an int, or a default you pass in. A small example finds planet as the first word longer than 5 letters, gets null and then none for a z, and 0 from an empty int array, with real output.
7 min readHow to Pass Any Number of Arguments to a Method with params in C#
params in C# lets a method take any number of arguments, which arrive as one array or collection. A small example calls Total with none, one and three numbers and prints count 3, total 35, passes an existing array, and uses a C# 13 params IEnumerable, with the build errors for params in the wrong place.
7 min readHow to Add, Subtract, Multiply and Divide Numbers in C#
Add, subtract, multiply and divide numbers in C# with +, -, * and /. A small example works with 17 and 5, where 17 / 5 gave 3 as whole numbers and 3.4 as doubles, and 2 + 3 * 4 gave 14, with real output, the DivideByZeroException and what happens past int.MaxValue.
7 min readHow to Switch on Two Values at Once with a Tuple Pattern in C#
A tuple pattern lets a C# switch expression match two values at once: put them in parentheses, such as (isCold, isRaining), and write one arm per combination. A small example picks clothes for all four weather combinations and builds with 0 warnings, with the CS8509 warning, the CS8502 and CS8510 errors and a swapped-order bug you can hit on the way.
6 min readHow to Find the Position of an Item in a List with FindIndex in C#
List<T>.FindIndex in C# returns the position of the first item that passes a test, or -1 when none does. A small example finds milk at index 1 in a shopping list, replaces it through that index, finds melon at index 3 with a start position, and gets -1 for z, with real output and the mistakes to avoid.
7 min readHow to Put an Attribute on a Lambda Parameter in C#
In C#, an attribute can go on a lambda's parameter, written inside the parentheses in front of it. A small example puts Description on the celsius parameter of a Celsius-to-Fahrenheit lambda, prints 100 C is 212 F, reads the description back with reflection, and shows the errors for missing parentheses and a wrong attribute.
6 min readHow to Convert a String to a double with double.Parse in C#
Convert a string to a double in C# with double.Parse and a culture. A small example reads "3.5" and "1.25" with the invariant culture and adds them up to 4.75, then shows why "3.5" read as German became 35, with real output, the FormatException for "$4.99" and Infinity for 1e400.
6 min readHow to Match Several Patterns with or in C#
The or pattern in C# matches a value against several patterns at once, so one switch arm or one is check covers them all. A small example sorts a, b, e and x into vowels and consonants with one arm for all five vowels and checks a grade with is 'A' or 'B', with the errors you get from ||, a variable inside or, and not without parentheses.
6 min readHow to Run Several Tasks at Once and Wait for All of Them with Task.WhenAll in C#
Task.WhenAll in C# waits for several tasks that run at the same time and gives back all their results in the order you passed them in. A small example makes tea, toast and an egg that take 3, 2 and 1 seconds, all done after 3.0 seconds instead of 6, with real output and what happens when two of the tasks throw.
8 min read