What is the usage of DelegatingHandler in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

4K+ Views

In ASP.NET Web API, a DelegatingHandler is a type of HTTP message handler that forms a chain of handlers to process HTTP requests and responses. Each handler in the chain can perform operations on the request before passing it to the next handler, and then process the response when it comes back up the chain. The DelegatingHandler class allows you to create custom server-side message handlers that can intercept, modify, or handle HTTP requests and responses globally across your Web API application. This is useful for implementing cross-cutting concerns like logging, authentication, caching, or request validation. Syntax ... Read More

Removing all nodes from LinkedList in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

252 Views

The LinkedList class in C# provides the Clear() method to remove all nodes from a LinkedList efficiently. This method removes all elements and sets the Count property to zero. Syntax Following is the syntax for the Clear() method − public void Clear() Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It modifies the LinkedList by removing all nodes. Using Clear() with Integer LinkedList The following example demonstrates how to remove all nodes from a LinkedList containing integers − ... Read More

How to add custom message handlers to the pipeline in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

711 Views

To create a custom Server-Side HTTP Message Handler in ASP.NET Web API, we need to create a class that must be derived from the System.Net.Http.DelegatingHandler. Message handlers allow you to intercept HTTP requests and responses, enabling cross-cutting concerns like logging, authentication, caching, or request modification. How Message Handlers Work Message handlers form a pipeline where each handler can process the request before passing it to the next handler, and process the response on its way back. This provides a powerful mechanism for implementing middleware-like functionality in Web API. Message Handler Pipeline ... Read More

Get an enumerator that iterates through StringCollection in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

205 Views

The StringCollection class in C# provides a GetEnumerator() method that returns a StringEnumerator object. This enumerator allows you to iterate through the collection elements one by one using the MoveNext() and Current properties. Syntax Following is the syntax for getting an enumerator from StringCollection − StringEnumerator enumerator = stringCollection.GetEnumerator(); Following is the syntax for iterating using the enumerator − while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current); } Using GetEnumerator() with StringCollection The GetEnumerator() method returns a StringEnumerator that provides MoveNext() and Current members for manual iteration − Example ... Read More

Get or set the element at the specified index in ArrayList in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

1K+ Views

The ArrayList class in C# provides an indexer property that allows you to get or set elements at a specified index using square bracket notation. This property provides direct access to elements by their position in the collection. Syntax Following is the syntax for accessing elements by index in ArrayList − // Get element at index object element = arrayList[index]; // Set element at index arrayList[index] = value; Parameters index − The zero-based index of the element to get or set. value − The object to store at the specified index ... Read More

How to return a string repeated N number of times in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

5K+ Views

There are several ways to repeat a string or character N number of times in C#. This article covers three effective approaches: using the string constructor for characters, string.Concat with Enumerable.Repeat, and StringBuilder for more complex scenarios. Using String Constructor for Characters The simplest way to repeat a single character is using the string constructor that takes a character and a count − string repeatedString = new string(character, count); Example using System; namespace DemoApplication { public class Program { ... Read More

C# Program To Sort Student Names in Descending Order Using LINQ

Siva Sai
Updated on 17-Mar-2026 07:04:36

387 Views

This tutorial demonstrates how to create a C# program that sorts student names in descending order using Language Integrated Query (LINQ). LINQ provides a powerful, readable way to query and manipulate data collections directly within C# code. Why Use LINQ for Sorting? LINQ offers several advantages over traditional sorting approaches − Readability − Clean, SQL-like syntax that's easy to understand Flexibility − Works with various data sources (collections, XML, databases) using the same syntax Abstraction − Focus on query logic rather than implementation details Lazy Evaluation − Query execution ... Read More

Get an enumerator that iterates through the Dictionary in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

604 Views

To get an enumerator that iterates through a Dictionary in C#, you use the GetEnumerator() method which returns an IDictionaryEnumerator. This enumerator provides access to both keys and values as you iterate through the dictionary's key-value pairs. Syntax Following is the syntax for getting a Dictionary enumerator − IDictionaryEnumerator enumerator = dictionary.GetEnumerator(); The enumerator is used with MoveNext() to advance through the collection − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Using Dictionary Enumerator with Integer Keys ... Read More

What are some of the fastest way to read a text file line by line using C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

2K+ Views

There are several fast and efficient ways to read a text file line by line in C#. The most commonly used methods are StreamReader.ReadLine, File.ReadLines, and File.ReadAllLines. Each method has its own advantages depending on the use case and file size. Using StreamReader.ReadLine StreamReader is the most memory-efficient approach for reading large files since it processes one line at a time without loading the entire file into memory. This method is ideal for processing very large files where memory usage is a concern. Example using System; using System.IO; using System.Text; namespace DemoApplication { ... Read More

C# Program to Split a String Collections into Groups

Siva Sai
Updated on 17-Mar-2026 07:04:36

567 Views

Welcome to this comprehensive tutorial on creating a C# program to split a collection of strings into groups using Language Integrated Query (LINQ). Whether you're a novice or an intermediate programmer, this guide will provide you with the insights necessary to understand the power of LINQ in C# and its applications in data manipulation. Understanding the Concept of Grouping in LINQ Grouping is a powerful concept in data manipulation that involves organizing data into categories based on specified criteria. In LINQ, the GroupBy method is used to group elements in a collection based on a key selector function. ... Read More

Advertisements