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.
Category: Defensive Programming
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. Read-only Fields
The article discusses best practices for checking strings for null in coding. It outlines three common methods: using == null, is null, or string.IsNullOrEmpty().
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
When designing custom attributes, Microsoft recommends sealing them to potentially enhance performance. Do sealing attributes indeed lead to improved performance? Check out this article to learn the answer.
Code It Any Way You Want: Optimizing Span Operations – Clear vs. Fill
This article compares two key search methods in dictionaries: using `Contains()` on the Keys collection and `ContainsKey()` method directly on the dictionary. It demonstrates examples for both approaches, highlighting Microsoft's recommendation of using `ContainsKey()`. The article suggests further examination of the performance aspect of these methods.
Collection Performance: Detecting Items in a ConcurrentBag<>
The comparison between using the Count property and the IsEmpty() method in a ConcurrentBag reveals that IsEmpty() is 2.95 times more efficient based on benchmark results. This indicates a significant performance advantage for utilizing IsEmpty().
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.
You must be logged in to post a comment.