Abstract Class in C#

In c#, Abstract class is a class that can not be instantiated on its own

abstract class in c#

  • In c#, Abstract class is a class that can not be instantiated on its own
  • It is typically used as a base class for other class.
  • Abstract class provides a way to achieve abstraction, because there you can just declare the methods (abstract methods) and implement them later.
  • It can contain both abstract methods (methods without implementation details) and non-abstract methods (method with implementation details).
  • Similar goal can be achieved with interface, but in abstract class you can also define non-abstract method. These methods are needed when you need to share some common functionality.
public abstract class Shape
{
 // it is the basic syntax of abstract class
}

Example:

[Read More]

Easiest Way to Handle Csv Files in Csharp

how to read and write to csv files in c#

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

find duplicates in c# 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

Use cases of c# dictionary

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]