Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 54 of 2547
Creating an empty HybridDictionary with specified case sensitivity in C#
The HybridDictionary class in C# is a collection that combines the benefits of both ListDictionary and Hashtable. It automatically switches from a list-based implementation to a hash table when the collection grows beyond a certain size. By default, HybridDictionary is case-sensitive, but you can specify case sensitivity behavior during initialization. Syntax Following is the syntax for creating an empty HybridDictionary with default case sensitivity − HybridDictionary dictionary = new HybridDictionary(); Following is the syntax for creating an empty HybridDictionary with specified case sensitivity − HybridDictionary dictionary = new HybridDictionary(bool caseInsensitive); ...
Read MoreGet the TypeCode for value type Int16 in C#
The GetTypeCode() method in C# returns a TypeCode enumeration that identifies the type of a value. For Int16 (short) values, this method consistently returns TypeCode.Int16 regardless of the actual numeric value stored. Syntax Following is the syntax for getting the TypeCode of an Int16 value − TypeCode typeCode = int16Variable.GetTypeCode(); Return Value The GetTypeCode() method returns TypeCode.Int16 for all short variables, which represents the 16-bit signed integer type. Using GetTypeCode() with Int16 Values Example using System; public class Demo { public static void Main() { ...
Read MoreSortedSet Class in C#
The SortedSet class in C# represents a collection of objects that is maintained in sorted order. Unlike regular sets, SortedSet automatically keeps elements sorted and ensures uniqueness − duplicate elements are not allowed. SortedSet is part of the System.Collections.Generic namespace and provides efficient operations for adding, removing, and searching elements while maintaining the sorted order. Syntax Following is the syntax for creating and using a SortedSet − SortedSet setName = new SortedSet(); setName.Add(element); Key Properties Property Description Comparer Gets the IComparer object that is used ...
Read MoreGetting the value at the specified index of a SortedList object in C#
In C#, the SortedList class provides the GetByIndex() method to retrieve the value at a specific index position. Unlike dictionary access by key, this method allows you to access values by their ordered position within the sorted collection. Syntax Following is the syntax for using GetByIndex() method − public virtual object GetByIndex(int index); Parameters index: The zero-based index of the value to retrieve from the SortedList. Return Value The method returns an object representing the value at the specified index position. If the index is out of ...
Read MoreFind the last node in LinkedList containing the specified value in C#
The FindLast() method in C# LinkedList is used to find the last occurrence of a node containing the specified value. This method searches from the end of the LinkedList towards the beginning and returns the last LinkedListNode that contains the specified value. Syntax Following is the syntax for the FindLast() method − public LinkedListNode FindLast(T value) Parameters value − The value to locate in the LinkedList. Return Value Returns the last LinkedListNode that contains the specified value, or null if the value is not found. Using FindLast() with ...
Read MoreHow to return custom result type from an action method in C# ASP.NET WebAPI?
In ASP.NET Web API, you can create custom result types by implementing the IHttpActionResult interface. This interface provides a flexible way to customize HTTP responses beyond the standard return types like Ok(), BadRequest(), or NotFound(). The IHttpActionResult interface contains a single method that asynchronously creates an HttpResponseMessage instance, giving you full control over the HTTP response. Syntax The IHttpActionResult interface has the following structure − public interface IHttpActionResult { Task ExecuteAsync(CancellationToken cancellationToken); } How It Works When a controller action returns an IHttpActionResult, Web API calls the ExecuteAsync ...
Read MoreGetting the Values in a SortedList object in C#
The SortedList class in C# is a collection that stores key-value pairs sorted by the keys. To retrieve all values from a SortedList object, you can use the Values property, which returns an ICollection containing all the values in sorted order of their corresponding keys. Syntax Following is the syntax for accessing values in a SortedList − SortedList sortedList = new SortedList(); ICollection values = sortedList.Values; The Values property returns an ICollection that can be iterated using a foreach loop − foreach (var value in sortedList.Values) { Console.WriteLine(value); } ...
Read MoreHow to resolve CORS issue in C# ASP.NET WebAPI?
Cross-Origin Resource Sharing (CORS) is a security mechanism that uses additional HTTP headers to allow web applications running at one origin to access selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. For example, consider an application with its front-end served from https://demodomain-ui.com and backend from https://demodomain-service.com/api. When the UI tries to make API calls to the backend, browsers restrict these cross-origin HTTP requests for security reasons, resulting in CORS errors. CORS ...
Read MoreCheck if SortedSet and the specified collection contain the same elements in C#
The SetEquals method in C# is used to check if a SortedSet and another collection contain exactly the same elements. This method returns true if both collections have identical elements, regardless of their order, and false otherwise. Syntax Following is the syntax for using the SetEquals method − public bool SetEquals(IEnumerable other) Parameters other − The collection to compare with the current SortedSet. Return Value Returns true if the SortedSet and the specified collection contain the same elements; otherwise, false. Using SetEquals with Different Elements ...
Read MoreGet a specific type nested within the current Type in C#
The GetNestedType() method in C# is used to retrieve a specific nested type (inner class) from within the current type. This method is part of the Type class and helps in reflection scenarios where you need to access inner classes dynamically. Syntax Following is the syntax for the GetNestedType() method − public Type GetNestedType(string name) public Type GetNestedType(string name, BindingFlags bindingAttr) Parameters name − The name of the nested type to retrieve. bindingAttr − Optional. Specifies how the search is conducted (public, non-public, etc.). Return Value Returns a Type ...
Read More