Category: CSharp
-
C# Basics: Delegates
Delegates are one of the most used features of C#. It allows you to pass a function as of function pointer. It is kind of same as function pointer of C++. Put simply, delegates are the same as a function pointer of C ++. It refers to another function. As noted in Microsoft official documentation:…
-
What is the Extension Method in C#?
Read full article on Infragistics blog I often get questions about the Extension Method in C#. The Extension Method was introduced in C# Version 3.0. and allows us to add functionalities in an existing class without modifying it, extending it, or re-compiling it. Essentially, the Extension Method allows us to add a new method to…
-
The Top 5 New Features in C#6.0
Visual Studio 2015 recently introduced a new version of C# named C#6.0. I would not say it has major features added like Extension Method or LINQ in C# 3.0 or Async/ Await in C# 5.0. However it has many features that simplify the syntaxes and improve the readability of the code. Major C# 6.0 features…
-
Simplifying the Liskov Substitution Principle of SOLID in C#
Before I start writing this article, I want to thank Steve Smith for his great course on the same topic with Pluralsight. This post is inspired by that course. Read full article on the Infragistics blog here The Liskov Substitution Principle says that the object of a derived class should be able to replace an…
-
C# basics: why we override Equals method
You may have come across questions, Why to override Equals method? How to determine whether two object are equal? How to determine whether two objects are identical? To get answer of all the above questions, let us consider Product class as listed next: We are creating two instances of the Product class, foo and…
-
C-Sharp Basics: What is Checked and Unchecked operations
You may have come across questions, What is checked and unchecked primitive operations? How to handle overflow in C-Sharp? Does CLR handles overflow or developers? So let us start with understanding a program. Consider the code listed below: On running you will get 44 as the output. There is one serious observation about the…
-
Property Initializers in C-Sharp 6.0
In the C-Sharp 3.0 a new feature Automatic property got introduced. It allows us to create a class as a bag of the setters and the getters. You can create a class as follows: Each property is backed by a backing filed. When you set value of the property, setter gets executed to set the…
-
Exception Filters in C-Sharp 6.0
So far we deal with the Exceptions as below. As you see in the following code snippet, we are catching the exception and displaying the error message. Challenge in the above snippet is that you cannot apply filter to the exception. Of course you can have if-else statement inside the try catch block but it…
-
Decorator Pattern in C#
Read full article on Falafel blog “Decorator pattern attach additional functionalities or responsibilities to an existing object at the runtime”. It adds new behaviour to an individual object without affecting other objects of the same class. New behaviour or functionalities can be either added dynamically at the run time or statically. The decorator pattern: ·…