C# Dynamic Type: Var vs dynamic keywords in C#

The dynamic keyword is used to define dynamic types. Dynamic type is used to avoid compile-time type checking. The compiler does not type-check dynamic type variables at compile time, instead, the compiler check the type at the run time. If the syntax of the statement is invalid, an error will be thrown at runtime.

Dynamic types are similar to object types, despite the fact that type checking for object type variables occurs at compile time rather than at runtime for dynamic type variables.

csharp dynamic type
C# dynamic type

Read more >>

C# Unsafe Code: Why do we need unsafe code in C#?

Unsafe code in C#

In general, the code written in C# is safe code that doesn`t directly access memory using pointers. It also doesn’t allocate raw memory. Instead, managed objects are created.
On the other hand, unsafe code in C# usually refers to a section of code that is not processed by the CLR (Common Language Runtime) and directly access memory using pointers.

Since pointers are complex and might result in memory-related errors like stack overflow, overwritten system memory, etc., extra caution must be taken while handling unsafe code.
By default, pointers are not supported in C#. However, the use of pointer variables is permitted by the unsafe keyword.

charp unsafe code

Read more >>

C# Events: Top 5 Differences between delegates and events in C#

C# Events: The Events enable a class or object to notify other classes or objects when some interesting thing happens to the object. A class that sends or raises the event is called the publisher, and the classes that receive or handle the event are referred to as subscribers.

There can be multiple subscribers to a single event. Typically, when an action takes place, a publisher raises an event. The subscribers who want to be notified when an action takes place should register or subscribe to handle specific events.

The following diagram shows the event in C#.

csharp events
C# event model

Read more >>

C# Hashtable vs Dictionary: When should you use a Hashtable or a Dictionary?

“In C#, a hashtable is a non-generic collection that can store key/value pairs of any data type. On the other hand, A dictionary is a generic collection that can store key/value pairs of specific data types.”

In this article, we will learn the differences between the Hashtable and Dictionary with examples.

C# Hashtable vs Dictionary
C# Hashtable vs Dictionary

Read more >>

C# Arrays: Everything You Need to Know About Array in C#

C# Arrays: An Array is used to store multiple values in a single variable, rather than declaring a separate variable for each element. It is a fixed-sized sequential collection of elements of the same type.
The data types of the elements in an array can be int, char, float, string, and so on, and they are stored in a contiguous location.

C# Arrays
C# Arrays

Read more >>

Types of Comments in C#: Single Line, Multiline and XML Comments

Comments-in-C-Sharp
Comments in C#

Introduction: Comments in C#

Comments are used in a program to make a section of code easier to understand. They’re used to make the code more readable and provide a formal description of it and how it works. 

The compiler ignores comments, so you may put them wherever in a program and not worry about them breaking it.

Read more >>

Generics in C#: A Comprehensive Guide with Code Examples and Explanations

Generics in C# allow you to write type-safe, reusable, and efficient code. In this comprehensive guide, you will learn everything you need to know about generics including how to create generic classes, methods, collections, and generic constraints. This article contains valuable information about C# generics that will help both beginners and experienced C# developers enhance their coding abilities.

C# Generics allow you to reuse the same code (class or method) with different data types. It refers to a generalized version of something rather than a specialized version.

Generics in C#
Generics in C#

Read more >>

Top 5 Difference between Call by Value and Call by Reference

In this post, we’ll look at a simple but difficult interview question in C#: Call By Value vs Call By Reference.

This is a question that both fresher and experienced developers are asked in interviews. It’s one of the most frequently asked questions by technical interviewers.

Call by Value and Call by Reference
Difference between Call by Value and Call by Reference

Read more >>

ASP.NET Core Middleware With Examples

In ASP.NET Core, middleware is a component that can be plugged into the request processing pipeline to perform some action for each request. It sits between the server and the application and is responsible for handling requests and responses.

asp-net-core-middleware
asp-net-core-middleware

Read more >>

C# Collections – Understanding collections in C# with [Examples]

Collections in C#
C# Collections types

Collections in C#

A collection in C# is a class that represents a group of objects. Collections can be used to perform various operations on objects, such as storing, updating, deleting, retrieving, searching, and sorting.

Collections are defined in the System.Collections namespace. They are a predefined set of classes for storing multiple items in a single unit.

Read more >>

WCF vs Web API: Top 10 Differences Between WCF and Web API

WCF (Windows Communication Foundation) is a framework for building service-oriented applications. It allows communication between applications on different devices, across computers and networks. WCF is part of the .NET framework, and it provides a runtime environment for applications that use distributed communication.

Web API is a framework for building HTTP services. It is a part of the ASP.NET platform and it allows you to create RESTful (representational state transfer) services, which can be consumed by a wide range of clients including web browsers and mobile devices.

This article will provide a practical comparison of WCF and Web API to help you decide which is the better option for your needs. We will discuss the differences between these two frameworks in detail.

WCF VS WEB API
WCF VS WEB API

Read more >>

C# 10 New Features: A Comprehensive Guide with Code Examples

As a programming language, C# has gone through several iterations, and with each new version, we see new features and enhancements that make programming with it even better.
C# 10, the latest language version, is no exception.

In this article, we will explore the new features of C# 10 and provide examples of how to use them in your code.

C# 10 New Features
C# 10 New Features

Read more >>

C# Struct vs Class |Top 15+ Differences Between Struct and Class

Difference Between Struct and Class in C#:

One key difference between structs and classes is that Structs are value types, whereas classes are reference types.

In the case of structs, they are copied by value, meaning that a complete replica of the data is created when passed or assigned. On the other hand, classes are copied by reference, meaning that only a reference to the original data is passed around rather than a full duplication.

C# struct vs class
C# struct vs class

Read more >>