Best of C# — July 2024
- 1
- 2
Game Developers·2y
Free Game development full course
A seasoned game developer is offering a free course to teach C# and Unity, targeting aspiring game developers. The course aims to make the learning journey easier and includes regular lectures. Interested participants are invited to join by contacting the instructor on Discord.
- 3
Community Picks·2y
Dependency Injection made simple.
Dependency Injection simplifies handling dependent objects, making code more flexible and decoupled. In JavaScript, passing connection objects through constructors exemplifies this. For strongly typed languages like C# and Java, interfaces help enforce consistent structures. This approach enhances code management and testing.
- 4
Towards Dev·2y
SOLID Principles in C#
The SOLID principles are a set of five key design principles for building maintainable and flexible software architecture: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. The post details each principle with examples in C#, providing guidelines to help keep classes focused and testable, favoring abstraction and composition over inheritance, and ensuring extensibility without modifying existing code.
- 5
freeCodeCamp·2y
How To Use LINQ in C# – With Code Examples
LINQ, part of the .NET framework, allows for powerful data querying through both language-level query syntax and method syntax. This post covers various LINQ methods such as `OrderBy`, `First`, `Single`, `SingleOrDefault`, and `Select` with examples on how to apply them. It also delves into deferred execution and method chaining, demonstrating how LINQ can optimize performance and allow for more complex, readable queries. Writing defensive code to handle changes in data over time is emphasized for error prevention.
- 6
ASP.NET Blog·2y
C# 13: Explore the latest preview features
C# 13 introduces new features focusing on flexibility, performance, and enhancing everyday use. Key updates include enhancements to params collections, new lock object improvements for mutual exclusion, index operator improvements, a new escape sequence for the ESC character, and the introduction of partial properties. Additionally, there are enhancements to method group natural type determination and relaxed restrictions for ref and unsafe contexts in async methods and iterators. The preview can be tried with the latest .NET 9 and Visual Studio 2022 updates.
- 7
habr·2y
Spans in C#: Your Best Friend for Efficient Coding
Spans in C# provide a powerful way to handle memory efficiently, reducing allocations and improving performance. They allow for direct manipulation of memory regions, support safe code practices, and are stack-allocated. This guide covers their use, differences between Span<T> and ReadOnlySpan<T>, and practical examples, including JSON parsing, converting arrays, and strings to spans. Ensuring proper scope and compatibility with development environments is crucial for optimal use.
- 8
The Coded Message·2y
Programming Portfolio
The programming portfolio showcases publicly available code written by the author. It includes both hobbyist and professional projects in languages such as Rust, C#, and Haskell. Highlights include a serialization format for serde-dbus in Rust, a blockchain app for Ledger Nano S in C#, and various hobby projects like a chess game and a Wordle clone in Haskell.
- 9
Code Maze·2y
How to Read appsettings.json in a .NET Console Application
Learn how to read and manage configuration settings using the appsettings.json file in a .NET console application. This guide covers adding the appsettings.json file to your project, installing necessary NuGet packages, setting up ConfigurationBuilder to read the JSON file, and accessing configuration sections either through key specification or binding to strongly typed objects. This ensures maintainability and flexibility in managing environment-specific configurations.
- 10
freeCodeCamp·2y
What is Primitive Obsession?
Primitive Obsession is a code smell where primitives like strings and integers are overused to represent complex concepts such as email addresses, phone numbers, and unique IDs. This leads to issues like weak type checking, poor readability, code duplication, and difficulty in refactoring. The post discusses the drawbacks of primitive obsession and offers strategies to design more robust data structures for better code correctness, maintainability, and data safety. It emphasizes the importance of encapsulation and being vigilant about special validation, comparison, and formatting rules for variables.
- 11
Code Maze·2y
Local Functions vs Lambda Expressions in C#
Local functions and lambda expressions in C# serve different purposes and have distinct performance characteristics. Local functions are methods nested within other methods and excel in performance since they can avoid heap allocation and use struct instead of class captures. Lambda expressions, while concise and useful for passing as delegates, generally require heap allocation and object instantiation. Local functions can be generic, recursive, and used as iterators, whereas lambda expressions struggle with these features. Thus, local functions are often more versatile and performant, especially when not using APIs that demand delegates.
- 12
C# Corner·2y
Differences Between IEnumerable and IQueryable in C#
Understanding the differences between IEnumerable and IQueryable in C# is crucial for optimal data manipulation and querying. IEnumerable is used for in-memory data collections and supports deferred execution, while IQueryable is designed for remote data querying and can be translated into query languages like SQL. Using IEnumerable is best for local data collections, whereas IQueryable is ideal for querying large external data sources efficiently.
- 13
- 14
Medium·2y
Hidden Gems of .NET: Tricks and Features Every Developer Should Know
Discover some lesser-known features and tricks in .NET that can significantly enhance your development experience. Learn about global using directives, string interpolation enhancements, Span<T>, top-level statements, source generators, file-scoped namespaces, nullable reference types, custom attributes, records, and .NET Interactive Notebooks.
- 15
C# Corner·2y
Discard Variable in C# .NET
The discard variable, introduced in C# 7.0 and represented by an underscore (_), is a special, read-only variable used to ignore values intentionally. This feature can lead to more readable and maintainable code by avoiding unnecessary variables. Common usage scenarios include deconstructing tuples, pattern matching, handling out parameters, and optimizing LINQ queries. The discard variable enhances code clarity and can aid in performance optimization by reducing memory usage.
- 16
Snyk·2y
Preventing SQL injection in C# with Entity Framework
SQL injection (SQLi) is a severe security threat that happens when malicious SQL code is injected into user inputs, potentially compromising the database. To avoid SQLi, it's crucial to avoid using string concatenation for SQL queries. Instead, Entity Framework (EF) offers secure options: LINQ for most queries, FromSqlInterpolated for raw SQL using string interpolation, and FromSqlRaw when explicit parameters are defined. Tools like Snyk Code can help detect unsafe code during development.
- 17
C# Corner·2y
Liskov Substitution Principle in C# with Example
The Liskov Substitution Principle (LSP) is one of the SOLID principles of object-oriented design, which ensures that objects of a superclass can be replaced by objects of a subclass without introducing errors. The post provided an example with a Bird class and an Ostrich class that violates LSP, and demonstrated refactoring the code by introducing an IBird interface and specific bird classes to adhere to LSP, making the code robust, maintainable, and scalable.
- 18
- 19
Code Maze·2y
Bridge Design Pattern in C#
The Bridge Design Pattern is a structural pattern in C# that helps decouple a class’s implementation from its abstraction, allowing the two to vary independently. This pattern uses interfaces and abstract classes as abstraction and implementation layers respectively, avoiding the explosion of subclasses that occur in inheritance-based designs. For example, by separating discount logic from delivery calculation in a pricing system, it allows different combinations of both without creating a subclass for each combination. However, it requires careful consideration due to its complexity and the shift of responsibility to client code.
- 20
C# Corner·2y
C# Abstract Class with Examples
Abstract classes in C# provide a blueprint for other classes, allowing for shared functionality, default behavior, and partial implementation. They contain abstract methods, which must be implemented by derived classes, as well as non-abstract methods that can be inherited. Abstract classes are essential for code reusability, extensibility, and maintainability, differentiating from interfaces which solely define method signatures. Understanding their usage is crucial for building scalable and maintainable applications in C#.