Code It Any Way You Want: Performance Considerations for Sealed and Internal Classes

This article explores the historical belief that sealed and internal classes in .NET might offer performance advantages, but suggests that in modern .NET runtimes, compiler optimizations, and hardware advancements, the difference in performance is likely negligible, emphasizing that design considerations should drive decisions regarding class sealing or internalization rather than performance concerns.

General Performance Tip: Type Conversion

This article explores type conversion in programming, comparing the traditional syntax with the newer "as" keyword in .NET. While the "as" keyword improves code readability, benchmark results suggest that the conventional method is slightly more performant, advising developers to stick with traditional type conversion unless significant performance improvements are observed with the "as" keyword.

Reference Type & Structure Performance: Constant vs. Read-only Property

This content discusses the performance of using a constant vs. a read-only property.

Code It Any Way You Want: Constants vs. Properties

The post discusses the importance of using constants for static numerical or string values in code, highlighting benefits such as clarity of intent. It provides an example of a read-only property for π and notes that .NET 10 benchmarks show similar performance for both methods. EditorConfig settings for identifying issues are also mentioned.

General Performance Tip: Choosing Between Conditional Statements – If, Switch, and Switch Expression Performance in C#

This article compares the performance of conditional if statements, switch statements, and switch expressions in C# code, with a focus on data retrieval.

Code It Any Way You Want: Performance Impact of Sealing Attributes

The excerpt discusses the recommendation to seal classes in .NET for design clarity and adherence to OOP principles, while noting that benchmark tests reveal non-sealed classes perform slightly better. Despite this, the author maintains sealing classes not meant for inheritance is essential for robust class design. An EditorConfig setup for checking this is also mentioned.

Collection Performance: Is LINQ Always the Most Performant Choice?

The article explores the performance implications of using LINQ for collection queries, finding that a conventional foreach() loop outperforms LINQ by 1.75 times in identifying items matching a given query. The conclusion suggests benchmarking to determine the optimal approach based on the nature of the query and elements being sought.

Code It Any Way You Want: Comparison of Passing Parameters in Methods

This article explores different methods of passing parameters into methods, including conventional, in operator, and ref readonly approaches, comparing their performance. Despite differences in syntax, benchmark results demonstrate similar performance among these methods.

Code It Any Way You Want: Optimal Parameter Passing – Array vs. Params Keyword

The article explores the performance differences between passing parameters as arrays or using the params keyword in C#. Despite similarities in speed, the author recommends using the params keyword for its ease of use during function calls.

Code It Any Way You Want: Checking Strings for Null

The article discusses best practices for checking strings for null in coding. It outlines three common methods: using == null, is null, or string.IsNullOrEmpty().