Microsofts Indices and Ranges page provides examples of the indices and range syntax available in C# (introduced in C#8). This syntax … Continue reading Using C# indices and range syntax to access elements in a sequence
Category: C# Blog
C# blog posts covering topics such as usage tips, little known features, new features in upcoming versions of the language, performance tips including BenchmarkDotNet benchmarks and more…
Using ToLower() or ToUpper() in C# to compare strings is not safe in all cultures
If you’re using Resharper, Roslynator or similar you’ll likely see string comparisons using ToLower() or ToUpper() flagged. Why are these … Continue reading Using ToLower() or ToUpper() in C# to compare strings is not safe in all cultures
Don’t use the C# var keyword everywhere in your code just to be consistent
Don’t use the var keyword everywhere in your code base just to be consistent. If using var removes clarity for … Continue reading Don’t use the C# var keyword everywhere in your code just to be consistent
Easier immutability with Init only properties in C# 9
C# 9 shipped with .NET 5 in November. One change included is init only properties which allow us to have … Continue reading Easier immutability with Init only properties in C# 9
Parsing a nested value from a JSON string in .NET Core 3 without needing a DTO
.NET doesn’t use Newtonsoft by default anymore (since .NET Core 3.0). A lot of the examples online show how to use … Continue reading Parsing a nested value from a JSON string in .NET Core 3 without needing a DTO
Generating sequential GUIDs which sort correctly in SQL Server in .net
Using a non sequential GUID in either a clustered or non clustered index is not ideal from a performance point … Continue reading Generating sequential GUIDs which sort correctly in SQL Server in .net
Converting numbers to strings without scientific notation in C#
C# will automatically convert numbers which are of type float, double or decimal and have a lot of precision (lots … Continue reading Converting numbers to strings without scientific notation in C#
Discouraging use of the var keyword and ternary if operator
I would always favour typing more code to make it more explicit, more readable and to ensure consistency in style … Continue reading Discouraging use of the var keyword and ternary if operator