Latest Posts On Code Maze

Tracing .NET Applications Easily With OpenTelemetry

Tracing .NET Applications Easily With OpenTelemetry

One of the fundamental concepts in the OpenTelemetry project is the ability to observe end-to-end requests through our applications, which is known as tracing. We achieve this by adding custom code to our .NET applications to emit this tracing information, which we...

Realistic Data Generation in .NET With Bogus

Realistic Data Generation in .NET With Bogus

In this article, we are going to learn what Bogus library is and how we can use it to generate fake data in .NET. We will create examples for generating data in different ways and show some additional community extensions we can use on top of Bogus. [sc name="github"...

Required Members in C#

Required Members in C#

 C# 11 introduces the concept of required members. Any code instantiating the containing class must initialize these members; otherwise, the compiler will issue an error while compiling it. In this article, let's learn how to use this feature to prevent bugs and catch...

How to Randomize a List in C#

How to Randomize a List in C#

C# has several built-in methods for working with arrays and lists, but what if you need to randomize a list of items? In this article, we'll look at some techniques we can use to randomize lists in C#. We'll also discuss some of the pros and cons of each technique and...

How to Get The List of Properties in C#

How to Get The List of Properties in C#

In this article, we are going to learn how to get the list of properties in C#, and also how to use the BindingFlags to filter the properties to retrieve. [sc name="github"...

Convert String and Int to Enum in C#

Convert String and Int to Enum in C#

Converting a string to an enum in C# is a call to Enum.Parse<T>() or Enum.TryParse<T>(). Converting an int to an enum is a cast. That asymmetry is the whole subject: one direction goes through a method that can reject bad input, and the other goes through...

Understanding PLINQ in .NET

Understanding PLINQ in .NET

In this article, we are going to explore PLINQ, which is the parallel implementation of LINQ. We are going to focus on when, and how to efficiently use it.  [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/csharp-linq/UnderstandingPLINQ"...

Boxing and Unboxing in C#

Boxing and Unboxing in C#

In this article, we are going to talk about boxing and unboxing in C#.  When we work with C# language constantly, we need to...

Encrypting and Decrypting a String in C#

Encrypting and Decrypting a String in C#

In this article, we will learn how encrypting and decrypting a string is done using C# and the Cryptography package that comes included with .NET. [sc name="github"...

Cryptography Implementations in .NET

Cryptography Implementations in .NET

Cryptography is the security backbone of what our modern society is built upon. This science has enabled us to keep data and communication safe from being compromised or stolen. We can find examples of its use in personal password managers up to the security aspect of...

Generic Attributes in C#

Generic Attributes in C#

In this article, we are going to learn how generic attributes help us implement better custom attributes through a practical example. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/csharp-advanced-topics/GenericAttributesInCSharp"...

Rebus in C#: The Lightweight .NET Service Bus

Rebus in C#: The Lightweight .NET Service Bus

Rebus is a lightweight, MIT-licensed service bus for .NET. We publish a typed message, implement IHandleMessages<T> to receive it, and Rebus takes care of the exchanges, queues, retries, and the error queue. It sits between our code and a broker such as...

How to Iterate Over JSON Objects in C#

How to Iterate Over JSON Objects in C#

Manipulating JSON objects is a common operation in applications. In this article, we will look at different ways of iterating over JSON objects in C#. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/json-csharp/IteratingOverJsonObject"...

OpenTelemetry in .NET – Basic Usage With Examples

OpenTelemetry in .NET – Basic Usage With Examples

Being able to debug our applications in an efficient manner is a very important aspect when it comes to designing and building applications. In a world of microservices, it becomes harder and harder to reason about our applications and where the source of a bug or...

ConcurrentBag in C#

ConcurrentBag in C#

ConcurrentBag<T> is a thread-safe, unordered collection in the System.Collections.Concurrent namespace. Any number of threads can add to it and take from it at the same time without a lock statement. The price of that is order. A bag keeps one queue per thread...

How to Add a BearerToken to an HttpClient Request

How to Add a BearerToken to an HttpClient Request

Often, in our daily routine, we have to deal with secure APIs and use a BearerToken to make HTTP requests. In this article, we are going to learn the correct way to add a BearerToken to an HttpClient request. [sc name="patreon-source-code"...

Task vs ValueTask in C#: When to Use Each

Task vs ValueTask in C#: When to Use Each

Return Task by default. Use ValueTask only for a method that is called constantly and usually finishes without ever awaiting anything (a cache lookup that normally hits, a buffered read that normally has data). The reason is what each one costs when it completes...

ASP.NET Core Select Tag Helper: asp-for and asp-items

ASP.NET Core Select Tag Helper: asp-for and asp-items

The select tag helper renders a <select> element from a model property. Two attributes do the work: asp-for names the property, and asp-items supplies the options. asp-for carries more weight than it looks. It sets the element's id and name, it decides which...

How to Update the Value Stored in a Dictionary in C#

How to Update the Value Stored in a Dictionary in C#

In this article, we'll be looking at ways to update a value stored in a dictionary. A dictionary is a class in C# that allows us to store a collection of key/value pairs in a strongly typed way. [sc name="github"...