How to Serialize/Deserialize a Dictionary Object in C#

The serialization and deserialization of .NET objects is made easy by using the various serializer classes that it provides. But serialization of a Dictionary object is not that easy. For this, you have to create a special Dictionary class which is able to serialize itself. The serialization technique might be different in different business cases.
Today, let’s discuss how to implement serialization/deseralization with a sample. Code is shared in the post, which you can use in your application. Continue reading and let me know if you have any other approaches.


Polymorphism in C# Without Classes

Imagine all the benefits you’d experience if you could somehow apply polymorphism in C# without classes and methods. First of all, there would be far less dependencies in your code, no abstract base classes or interfaces that could potentially break your code in the future, no method signatures that could potentially break in the future, and no static types that could potentially break in the future. Sounds too good to be true? Read on my friend, and I’ll show you the glory.
Believe it or not, but the above is actually a functioning piece of computer code. It is an invocation to an “Active Event" who’s name if "", and it takes two arguments; arg1 and arg2. Its C# implementation might look like the following.


C#: When to Use ‘when’

C# 6 introduced the when keyword. The when keyword is a way to filter an exception in a catch block by some specific criteria. It was later extended to case statements in C# 7. I’ll focus on when to use it in exceptions in this post and address its use in a case statement in another post.
Catch Without When
Let’s say you want to handle the same type of exceptions using different criteria. A common scenario for this is an HttpException. When you catch an HttpException, the response code is available on the ResponseCode property. Depending on the response code, you may want to take different actions.


Important Tips to Write Clean Code in C#

I remember those days when I started my career in programming. I struggled to write a piece of code and who cared for the coding standards at that time. As time went on, I got abetter command over programming and was able to think of particular scenarios to solve problems. From the start of my career until today, I have found a continuity, and that is learning. At that stage, I was learning to manage basic things and, now, I am learning to handle the problems. So, in life, learning is a never-ending process. Every day, we learn something, whether it’s from reading articles, watching videos, or by our own mistakes or success in this programming environment.
As per my experience, we should not write our code like a layman. We should follow some coding standards to write clean, reusable, readable, and maintainable code.


What’s New in .NET Core 2.1

.NET Core 2.1 was officially released on May 30. I will summarize what’s new for all its parts – .NET Core itself, Entity Framework Core, and ASP.NET Core. You can also check out our article on the .NET Ecosystem to fully understand your options before you start your next project.
.NET Core 2.1
First, you will need either Visual Studio 2017 15.7 (or higher), Visual Studio Code, or Visual Studio for Mac in order to fully leverage this version. Docker images have been published at the Microsoft Docker repo. It is important that you upgrade since .NET Core 2.0 will reach end of life for Microsoft support in October 2018. There are no breaking changes, only a couple of useful additions.


Basic C# Code to Find Out the Occurrence of Each Character in a String

Recently I went to an interview where the interviewer asked me to write some basic code to find out the occurrence of each character in a string.
I managed to do that using some loop, but it was not an optimal solution. The complexity, O(n), for that code was fairly high. I’ve continued to play with the code since, and have found a lot of options to solve this problem.


Code-First Approach With ASP.NET MVC Framework

In this article, we’ll learn how to perform CRUD operations with a code first approach in an MVC application. Here, we will create an MVC structure that will help to change in the Model Class and that change will update it in the database. Microsoft’s Entity Framework (EF) avoids working directly with the database and creates the database per the model classes’ requirements. We will not use visual model designer (EDMX) completely but will create POCO classes first and then create the database from these POCO classes.
Recommended Prerequisites

Visual Studio 2010 SP1
SQL Server

Step 1
Open Visual Studio and select “File” >> “New". Then click on Project (remember, don’t go with the option ‘File->New->Website’).


Creating Your Own Validation Attribute In MVC and Web API 2.0

Data validation in an application is one of the major tasks for the developer now-a-days. Data validation is the process of ensuring that the data entered by any users is correct and is useful. It uses routines, often called validation rules, validation constraints or check routines, which check for the correctness, meaningfulness, and security of data, that gets put into a web application. These rules are mainly implemented in UI, business logic, and databases.
If we check in any web application, we will mainly find validations in the UI. As the user interface is the primary source, where the user can enter invalid data in the application, we mainly focus on UI validation.


Create Windows Services in C#

Here I’m going to explain Windows Services in C# .NET.

Introduction of Windows Services.
How to create Windows Services in C# .NET.

Windows Services normally start when the OS boots and runs an application in the background. Windows Services executes applications in its own session. It either starts automatically or we can manually pause, stop, and restart it.