Skip to content

Category: C#

C# has a lot of features , some of witch we will explore here in this blog!
Let’s start excavating!

AutoMapper C#

When it comes to different layers of a solution communicating there are always DTOs (Data Transfer Objects) going back and forth and inevitably there is a lot of mapping. If there are external libraries or even 3rd party services then mapping an external object to the one our application already uses becomes tedious and error prone task. (Dont’t even get me started with SPA’s Angular JWT and all that jazz.) Thankfully for those of who develop in C# there is AutoMapper. AutoMapper As i noticed from my NuGet package manager, AutoMapper has been downloaded more than 22 million times! That…

Leave a Comment

Anonymous Methods C#

Last time we talked about Delegates, now we’ll look into the concept of anonymous methods that truly shines with the use of delegates. The Delegate ‘Clutter’ In order to use a Delegate you must do 4 things: Anonymous Methods at work By using anonymous methods, we could change step 3 and assign a method ‘on the fly’ without creating a new one The code can be simplified even more Keep in mind that if you have break/continue statements inside your anonymous method the target should remain inside the code block! If you want more information about the scope of the…

Leave a Comment

Delegates C#

A Delegate by definition is a person sent or authorized to represent others. The key concept here is ‘Represent others’. Delegates are used to represent other methods. Delegates at work Start by looking the example below, this is how we declare a simple Delegate. It is just like any other variable but instead of holding an integer value, it holds a method that can be executed. Now that we have declared our delegate we associate any method from any class as long as it matches the signature and the return type of the delegate. The method below is a valid…

Leave a Comment