The FrozenDictionary is a thread-safe, immutable, read-only dictionary optimized for fast lookups. It outperforms the Dictionary, reducing iteration and lookup times significantly.
Category: Coding Standards
DotNetDave Rocks On .NET Live: Performance Improvements in .NET 8
On June 10th, 2024 at 9 AM PST, I'll be appearing on "On.NET Live" for the second time. We'll delve into code performance in .NET 8 through the Code Performance Game. Join the live show for an engaging session. For more details, visit https://youtu.be/4WX14dsnKsg.
256 Seconds with dotNetDave: Handling Exceptions Part 1 – Reusable Assemblies
This content discusses exception handling in Microsoft .NET, focusing on application layer and reusable assemblies. It offers insights on preventing exceptions and notifying calling code, and references a related book. The principles are noted to be applicable to other programming languages.
Serializing Objects: Efficient Serialization and Deserialization of Collections with JsonSerializer
The article demonstrates the ease of serializing and deserializing collections using JsonSerializer.
Optimizing Collection Examination: A Comparative Analysis of Predicate Methods in C#
The article explores four methods for examining items in a collection using predicates, with a focus on performance. A Twitter poll revealed that over 50% of developers favored the LINQ Any() method, prompting the author to verify its efficiency in comparison to other options like Count() and Exists().
Understanding and Utilizing Common Attributes in Classes in Microsoft .NET
Attributes in .NET provide crucial metadata that enhances code clarity, tooling support, and developer experience. They enforce contracts, improve static analysis, and facilitate safe coding practices. By thoughtfully utilizing attributes like [DisallowNull], [DebuggerDisplay], and [DefaultValue], developers can create expressive, maintainable, and user-friendly APIs that benefit both current and future projects.
Code It Any Way You Want: Initializing Reference Type Static Fields Inline for Enhanced Code Readability
The article advocates for initializing reference type static fields inline to enhance code readability and prevent unexpected behavior caused by uninitialized static fields. Microsoft recommends initializing these fields at the point of declaration to improve clarity. The article provides examples demonstrating the issue and the recommended solution, emphasizing the use of static constructors for initialization.
Code It Any Way You Want: Expression-Bodied Methods vs. Traditional Methods
The article discusses the use of expression-bodied methods in .NET as an alternative to traditional methods for creating simple functions. It presents a comparison between the two methods in terms of syntax and performance. Despite the syntactical differences, benchmark results show that both methods demonstrate similar performance characteristics.
General Performance Tip: Retrieving the Nullable Value from a Reference Type
The article discusses two methods for retrieving nullable values from reference types in C#, showcasing examples using the ternary conditional expression and the null coalesce approach. Benchmark results indicate that the null coalesce approach demonstrates 1.12 times higher efficiency in performance compared to the ternary conditional expression.
Collection Performance: Exercise Caution When Using Take() with a Basic Count
The article advises caution when using the LINQ method Take() with a basic count, suggesting that a range might be recommended by code analyzers. However, benchmark results indicate that using Take() with a simple count is 1.63 times faster than employing a range in such cases.

You must be logged in to post a comment.