C# List with examples

In this article, we will learn about the C# list with the help of multiple examples.

List<T> is a dynamic collection that contains multiple objects of the same data type that can be accessed using an index.

It is similar to an array but can grow or shrink in size. Lists are commonly used to store and organize data in a sequential manner. It can dynamically perform operations like adding, searching, shorting, and removing elements from a collection.

The following diagram illustrates the methods and properties of the List<T> class.

C# List
List in C#

Read more >>

C# Access Modifiers: Everything You Need to Know (With Examples)

One of the fundamental features of C# is the use of access modifiers. These modifiers control the accessibility of classes, methods, and variables in your code.

In this article, we will take a comprehensive look at C# access modifiers, exploring their various types, their effects on code, and best practices for using them.

Access Modifiers in C#
C# Access Modifiers

Read more >>

C# Dictionary – How to Use a Dictionary in C# [With Examples]

A Dictionary in C# is a collection that stores a set of keys and values, similar to a Hashtable. Dictionaries are useful for storing data that needs to be quickly retrieved using a key.

  • In C#, a Dictionary<TKey, TValue> is a generic collection that stores key/value pairs data organized by the unique key.
  • In C#, the Dictionary class is part of the System.Collections.Generic namespace. It is a dynamic collection that can be resized on-the-fly, allowing you to add or remove items as needed. It means that you don’t have to pre-define the size of the dictionary, and it can grow or shrink depending on the data being stored.
C# Dictionary
C# Dictionary

Read more >>

C# Exception: C# Exception handling best practices

An exception is defined as an event that occurs during the program execution that is unexpected by the program code. Exception handling is important because it handles an unwanted exception so that your program code does not crash and remains meaningful to the user.

In this article, we will discuss the exception types and exception handling in C# using try, catch, and finally blocks.

exception handling in C#
C# Exception Handling

Read more >>

C# Enum: How to use enumeration type in C#?

What is an enum in C#?

An enum, or enumeration, is a value type in C# that consists of a set of named constants called the members of the enum. Enums are useful when you have a fixed set of values that a variable can take on, such as the days of the week or a set of predefined options.

Enums are value types, so they are stored in the stack rather than the heap. This means that they are faster to access than reference types, but they also take up more memory.

In this post, we will learn the proper usage of an enum in c# with multiple examples.

C# Enum
C# Enums

Read more >>

Extension methods in C#: Everything You Need To Learn (2023)

Extension Methods in C#
Extension Methods in C#

An extension method in C# is a feature that allows you to inject new methods into existing classes without changing their source code. 

It allows you to create additional methods that can be used as if they were a regular method of the original class. 

Extension methods are static methods defined in a static class. They use the “this” keyword with the first parameter, representing the type extended by the extension method.

Read more >>

OOPs Concepts in C# with Examples (2023)

Are you interested in learning about the fundamental concepts of Object-Oriented Programming (OOP) in C#? If so, you’re in the right place! This article will provide a comprehensive introduction to OOPs concepts in C#.

This post will go through object-oriented programming in C# and the four basic OOPs concepts.

C# OOP four basic OOPs concepts
C# OOP four basic OOPs concepts

Read more >>

Var keyword in C#: Best Practices and Examples

VAR Keyword in C#
VAR Keyword in C#

Introduction: var keyword in C#

In C# 3.0, the var keyword was introduced to declare an implicit type local variable that could hold any data. However, it’s important to remember that when using var, you must ensure the variable is assigned a value during declaration.

In simpler terms, var lets us create a variable without deciding its type beforehand. It’s like telling the compiler, “Hey, you decide the type based on what value I assign to this variable.” However, it’s important to note that when we declare a variable with var, we must also initialize it with a value right at the beginning.

Read more >>

Understanding C# Delegates (with Examples)

In simple terms, a delegate in C# is like a pointer to a method. It allows you to refer to a method by its name and invoke it later. Think of it as a “method container” that holds a reference to a particular method with a specific signature (parameters and return type).

Delegates In C#
C# delegate

Read more >>

Lock keyword in C# | Thread Locking In C#

The lock keyword in C# is used to place around a critical section of code, where we want to allow only one thread to access the resource at a time. Any other thread cannot access the lock and it waits for the lock to be released.

In this post series, we will go through the understanding of the lock keyword,  monitor, mutex, and semaphore available in C#.

All of these classes (lock, monitor, mutex, and semaphore) provide a synchronization mechanism to protect the shared code or resources in a multithreaded application.

CSharp Lock keyword in multithreading
C# Lock keyword

Read more >>

Multithreading in C#

In C#, multithreading is the ability of a central processing unit (CPU), or a single-core or multi-core processor, to execute multiple threads concurrently. This allows the program to perform multiple tasks simultaneously, making the program more efficient and responsive.

Multithreading in CSharp
Multithreading in C#

Read more >>

C# Reflection: Everything You Need to Know about Reflection in C# (With Examples)

Reflection in C# is the process of retrieving metadata of types, modules, assemblies, and more during runtime. With reflection, you can dynamically create an instance of a type, associate a type with an existing object, obtain the type of an existing object, and call its methods, fields, and properties.

In this article, we will explore the concept of C# Reflection, its hierarchy, when to use it, and some examples of its implementation.

C# Reflection
Reflection in C#

Read more >>