The article highlights the importance of adding an explicit cast in foreach loops when dealing with collections to avoid potential runtime issues caused by hidden casting. It also suggests simplifying the code using LINQ and optimizing performance by using `AddRange()`.
Category: .NET
Rockin’ the Code World Season 4: Special Guest Simon Painter
Join the 93rd show on C# Corner TV on December 16th, 2023, featuring Simon Painter, Senior Software Developer for Mueller Dairies, Ltd. The show includes an extensive interview with Painter, discussions on functional programming in C#.
Microsoft .NET Code Analysis: Make Collection Properties Read-Only
The article discusses the common programming practice of providing access to data collections through properties and highlights the issue of mutability in such properties, which can lead to undesirable collection replacements. To adhere to best practices, the article recommends either removing the property setter or using the init modifier to make the property read-only, emphasizing that read-only properties with collections are supported by binary and XML serialization.
Microsoft .NET Code Analysis: Simplify LINQ Expressions
The article discusses simplifying LINQ expressions in source code by eliminating unnecessary Where() methods and placing predicates directly in FirstOrDefault(). This not only improves code readability but also demonstrates a 1.9 times performance improvement in .NET 8.
Microsoft .NET Code Analysis: Utilize the Pattern Matching ‘not’ Operator
The article discusses how developers can improve code performance and readability by replacing explicit type checks with pattern matching, eliminating the need for redundant type conversions and enhancing code efficiency.
Microsoft .NET Code Analysis: Utilize Pattern Matching to Eliminate the Need for an ‘is’ Check
The author identifies inefficiencies in type conversions within a code sample from the Entity Framework codebase, suggesting improvements through pattern matching. They note 22 instances requiring fixes and recommend using their updated EditorConfig file for similar analyses. Feedback on their open-source project, Spargine, is welcomed.
Analyzing Performance Issues in Microsoft .NET 8
The author details extensive performance benchmarking of .NET 8, showcasing its notable improvements but also highlighting areas of performance regression compared to .NET 6. The areas of regression include slows in object creation, disposing, checking for null, array creation, LINQ methods, string handling, string compression, finding strings, encoding and decoding, and certain LINQ APIs and Lambda methods. He encourages developers to benchmark their code before transitioning to .NET 8.
Rockin’ the Code World Season 4: Special Guest Olia Gavrysh
On December 2nd, 2023, C# Corner TV will host show #92, featuring guest Olia Gavrysh, a Senior Product Manager from Microsoft .NET team. Gavrysh will discuss modernizing .NET applications, strategies for migrating to Azure, and her experiences in the .NET space. The show will also feature additional segments, including a philanthropic initiative to assist slum orphans in Delhi, India.
Microsoft .NET Code Analysis: Use nameof() To Retrieve the Parameter Name
The article discusses the importance of using `nameof()` in code to retrieve parameter names, highlighting how it helps prevent issues when parameter names change during refactoring by automatically updating them in exception handling. Additionally, it mentions that `nameof()` provides performance benefits by generating names during the build process rather than at runtime.
Microsoft .NET Code Analysis: Choosing Between String.Contains() and String.IndexOf()
In this article, we explore Microsoft's recommendation to utilize the String.Contains() method instead of String.IndexOf() for improved code readability. We provide code examples to illustrate this suggestion and discuss its relevance in the context of common coding practices, referencing its application in Entity Framework source code and adherence to coding standards like CA2249.

You must be logged in to post a comment.