Abstraction in C#

Abstraction in C#

šŸ“¢ Updated and refinded at : 21-feb-2025

Abstraction allows you to focus on the relevant details of an object while ignoring unnecessary complexities.
This is achieved by defining a simplified representation of an object that hides the implementation details and exposes only the necessary features.
In practical terms, abstraction is implemented through abstract classes and interfaces in languages like C#.

šŸ“ŗOther OOPs related articlesĀ :

[Read More]

Fluent Validation in Dotnet Core

Fluent Validation in Dotnet Core

Fluent validation

Fluent validation is an open source library for validating the models, which is free as of I am writing this article.

šŸ“¢ šŸ“ Last Updated: 25-March-2025

Why fluent validation?

If you already have used data annotation for validation, then you must be aware of the validation inĀ .NET. So you might be thinking why do we need a fluent validation then.

Fluent validation helps you to separate validation logic from your models. That makes your code clean. If you have complex validation logic, then you want to define it separately rather than making your model unreadable.

[Read More]

Uploading Images in Blazor Server

Uploading Images in Blazor Server

In this blog post we are going to learn how to upload files in the blazor server application. I am going to upload images in this tutorial but you can upload any file (i have created reusable code).

šŸ’»Source Code: https://github.com/rd003/BlazorFile/

High levelĀ overview

We will upload images to a folder of a local machine ( on a production you have to use cloud storage) with a unique name (e.g. sd$3abccc3$1.png ), that name is going to save in database.

[Read More]

Easiest Way to Handle Csv Files in Csharp

Easiest Way to Handle Csv Files in Csharp

In this tutorial we will se how to read and write data to csv file. It is pretty much easy if you have some external library for that. We are definitely going to use a library and that will be CsvHelper.

You can also check the video version of this tutorial.

First and foremost, create a c# console application inĀ .net core. After that we need to install a nuget package, which is**CsvHelper**

[Read More]

Multiple Ways to Find Duplicates in Csharp Array

Multiple Ways to Find Duplicates in Csharp Array

In C#, we can use various approaches to find duplicate elements in array. Each have pros and cons. We will use 3 approaches in this article.

  1. Using a HashSet
  2. Using a Dictionary
  3. Using LINQ

Lets take this array as an example, from this array we will extract distinct numbers and duplicate numbers.

int[] numbers = { 4,7, 2, 3, 4, 5, 3, 6, 7, 8,1, 8 };

We will use this array in all three approaches. So let’s understand one by one.

[Read More]

C# Dictionary and Its Use Cases

C# Dictionary and Its Use Cases

What is dictionary?

Dictionary is a collection, that store the value in the form of key value pair. It allows you to quick access of value using the key. This data structure is widely used in programming because of its fast look-up time, which makes it ideal for applications that require quick data retrieval

šŸ‘‰ You can not add duplicate key in dictionary

Creating a dictionary:

[Read More]

Catch Exception Globally in Dotnet Core Apis

Catch Exception Globally in Dotnet Core Apis

There are to ways of catching exception inĀ .net core, one is using try/catch and other one is catching them globally. Although there is nothing wrong with try/catch blog, it is an elegant way of exception handling. Although you can also catch exceptions globally, If you want to log errors in one place. There are various approaches to achieve this, but we will create the custom middleware to achieve it.

[Read More]

Output Caching With Dotnet 7

Output Caching With Dotnet 7

What isĀ Caching?

Caching is a process of temporarily storing frequently accessed data or resources in a faster and closer location to the user or application, with the goal of reducing the time and resources needed to retrieve that data from its original source. By keeping a copy of the data nearby, caching enables quicker access and improves the overall performance and responsiveness of applications.

[Read More]

JWT Authentication and Role Based Authorization in Dotnet Core

JWT Authentication and Role Based Authorization in Dotnet Core

JWT

According to jwt.io JSON Web Tokens are an open, industry standard RFC7519 method for representing claims securely between two parties.

When we create REST APIs, then we don’t want that any one can access those apis. REST APIs, will only be accessed by the authenticated user. We authenticate our user with the help of jwt.

How jwt works?

First, we give an authentication endpoint to user, where he/she puts credential, in return we give a jwt token to user which have an expiry date. To consume any protected resource, user need to pass jwt token on authorization header.

[Read More]

Create Sln File With Multiple Projects

Create Sln File With Multiple Projects

In this article we will learn how to create aĀ .net core project with a Solution (sln file) that contains multiple projects. I know most you guys use visual studio for c# related stuff, but it would be benificial for person who likes to switch with vs code ocassionally, like me or who use linux and forced to useĀ .net cli. Although if you are a new developer and have windows operating system, I will recommend visual studio, because it is the best possible IDE for c# development.

[Read More]