Programming Articles

Page 63 of 2547

How can we test C# Asp.Net WebAPI?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

Testing ASP.NET Web API involves sending HTTP requests and receiving responses to verify that your API endpoints work correctly. There are several effective methods to test Web APIs, including using Swagger for interactive documentation and testing, and Postman for comprehensive API testing. Let us create a sample StudentController to demonstrate different testing approaches − Student Model namespace DemoWebApplication.Models { public class Student { public int Id { get; set; } public string Name { get; set; ...

Read More

Check if an Array has fixed size or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 197 Views

In C#, all arrays have a fixed size once they are created. You cannot change the length of an array after initialization. To check if an array has a fixed size, use the IsFixedSize property, which always returns true for arrays. Syntax Following is the syntax to check if an array has fixed size − bool isFixed = arrayName.IsFixedSize; Using IsFixedSize Property Example using System; public class Demo { public static void Main() { string[] products = new ...

Read More

What is ViewData in ASP .Net MVC C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

ViewData is a dictionary-based container in ASP.NET MVC that enables data transfer from Controller to View. It stores key-value pairs where keys are strings and values are objects, making it a flexible but loosely-typed data transfer mechanism. ViewData is valid only during the current HTTP request and provides one-way communication from controller to view. Since it uses string keys and object values, it requires explicit casting when retrieving data and does not provide compile-time type checking. Syntax Following is the syntax for storing data in ViewData − ViewData["keyName"] = value; Following is the ...

Read More

Removing all entries from the StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 127 Views

The StringDictionary class in C# provides a collection of string key-value pairs. To remove all entries from a StringDictionary, you use the Clear() method, which empties the entire collection in a single operation. Syntax Following is the syntax for removing all entries from a StringDictionary − stringDictionary.Clear(); Parameters The Clear() method takes no parameters and returns void. It removes all key-value pairs from the StringDictionary and sets the Count property to zero. Using Clear() Method Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 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
AmitDiwan
Updated on 17-Mar-2026 245 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
Nizamuddin Siddiqui
Updated on 17-Mar-2026 695 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
AmitDiwan
Updated on 17-Mar-2026 198 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
AmitDiwan
Updated on 17-Mar-2026 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
Nizamuddin Siddiqui
Updated on 17-Mar-2026 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
Showing 621–630 of 25,467 articles
« Prev 1 61 62 63 64 65 2547 Next »
Advertisements