Latest Posts On Code Maze

System.Linq.Dynamic.Core: Dynamic LINQ in C#

System.Linq.Dynamic.Core: Dynamic LINQ in C#

System.Linq.Dynamic.Core lets us write LINQ queries as strings. Where typed LINQ takes a lambda, Where(e => e.Department == "IT"), the library takes text, Where("Department == @0", "IT"), and parses it into the same expression tree. We need that when the shape of a...

C# using static Directive: How and When to Use It

C# using static Directive: How and When to Use It

The using static directive lets us use a type's static members, constants, enum values and nested types without writing the type name each time. It arrived in C# 6, and C# 10 added a global form that covers the whole project. It doesn't import everything, though. The...

Null-Coalescing ?? And Null-Coalescing Assignment ??= Operators in C#

Null-Coalescing ?? And Null-Coalescing Assignment ??= Operators in C#

In this article, we are going to find out what null-coalescing operator ?? and null-coalescing assignment ??= operators are and how to use them. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/csharp-operators/NullCoalescingOperator"...

SortedSet in C#: Sorted Unique Values, Ranges and Comparers

SortedSet in C#: Sorted Unique Values, Ranges and Comparers

A SortedSet in C# is a data structure that stores unique elements and keeps them in sorted order, whatever order we add them in. It also hands us its smallest and largest element, a live view of any range, and the classic set operations such as union and intersection....

How to Use HTML Agility Pack in C#

How to Use HTML Agility Pack in C#

In this article, we're going to learn how to use HTML Agility Pack in C# and review some examples of its most important features. ...

Tasks vs Threads in C#

Tasks vs Threads in C#

In this article, we are going to look at the main differences between Tasks and Threads. They are both used for concurrent programming, but Tasks were later introduced with .NET Framework 4. [sc name="github"...

Concurrent Collections in C#: Thread-Safe Lists and Sets

Concurrent Collections in C#: Thread-Safe Lists and Sets

Concurrent Collections in C# are a set of collections designed for synchronized multi-thread access. We can find them under the System.Collections.Concurrent namespace, and they cover dictionaries, queues, stacks and bags. There is no concurrent list or concurrent...

HashSet in C#: Methods and Set Operations

HashSet in C#: Methods and Set Operations

A HashSet<T> in C# is a collection that holds each value at most once and finds any of them in constant time on average. Adding a value that is already in the set changes nothing and tells us so. [sc name="github"...

How to Convert DataTable to JSON in C#

How to Convert DataTable to JSON in C#

Converting DataTable to JSON is one of those tasks that we come across from time to time and it seems like there should be a built-in method to do it. Unfortunately, that is not the case and we need to figure out a way to do it on our own. In this article, we will...

Advanced LINQ

Advanced LINQ

LINQ is an extremely useful library with many applications. These applications are not all utilized or understood equally. In this article, we are going to take a look at some advanced LINQ capabilities to perform grouping, joining, partitioning, and even converting...

Constructor Overloading in C#

Constructor Overloading in C#

In this article, we are going to talk about constructor overloading in C#. We'll look at the different ways to implement it in an application.  While we look at constructor overloading in this article, we have an existing article on constructors that can act as a...

IComparable vs IComparer vs Comparison Delegate in C#

IComparable vs IComparer vs Comparison Delegate in C#

IComparable<T> gives a type its one default sort order, IComparer<T> puts a sort order in a separate class, and the Comparison<T> delegate is a sort order written as a method or a lambda. All three answer the same question about two objects: which...

Using OData with ASP.NET Core Web API

Using OData with ASP.NET Core Web API

In this article, we will learn how to use OData with ASP.NET Core Web API services. OData (Open Data Protocol) is an open protocol that defines a set of best practices for building and consuming RESTful APIs. Initiated by Microsoft in 2007, it has become an OASIS...

Common C# Programming Mistakes

Common C# Programming Mistakes

In this article, we are going to look at some common C# programming mistakes. We are pretty sure that there are a lot more mistakes that developers make while writing their projects, but here, we will try to summarize the ones we often noticed while working with other...

Localization in ASP.NET Core

Localization in ASP.NET Core

Making websites multi-lingual allows users from around the globe to use our applications in their native language. In this article, we are going to see how ASP.NET Core provides us with the ability to enable localization to support different languages and cultures. ...

Capitalize the First Letter of a String in C#

Capitalize the First Letter of a String in C#

To capitalize the first letter of a string in C#, upper case the first character and copy the rest unchanged. string.Create() does it in a single allocation: string.Create(input.Length, input, static (chars, str) => { chars[0] = char.ToUpperInvariant(str[0]);...

IndexOutOfRangeException in C# and How to Fix It

IndexOutOfRangeException in C# and How to Fix It

IndexOutOfRangeException is the exception .NET throws when we read or write an array element at an index that doesn't exist. For a normal zero-based array, that is a negative index or one equal to or greater than the array's Length. On arrays its message is "Index was...

Boosting Performance With Sealed Classes in .NET

Boosting Performance With Sealed Classes in .NET

In this article, we are going to learn how we can boost performance with sealed classes in our .NET projects. By default, all classes in C# are open for inheritance. We can use the sealed keyword to prevent inheriting from the class and improve performance for certain...