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 More
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 More
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 More
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
Filters in ASP.NET Web API provide a way to inject additional logic at different stages of request processing. They enable cross-cutting concerns such as authentication, authorization, logging, and caching without cluttering your controller logic. Filters can be applied declaratively using attributes or programmatically, offering flexibility in how you handle these concerns. Web API supports several types of filters, each serving a specific purpose in the request pipeline. Understanding these filter types helps you choose the right approach for implementing various functionalities in your API. Types of Filters Web API Filter Pipeline ... Read More
A perfect number is a positive integer that equals the sum of its proper divisors (all divisors excluding the number itself). For example, 6 is perfect because its proper divisors (1, 2, and 3) sum to 6. Proper divisors are numbers that divide evenly into the given number without leaving a remainder. Perfect Number: 6 1 2 3 = 6 6 ÷ 1 = 6 6 ÷ 2 = ... Read More
The OrderedDictionary class in C# provides the GetEnumerator() method to obtain an IDictionaryEnumerator object. This enumerator allows you to iterate through the key-value pairs while maintaining the insertion order of elements. The IDictionaryEnumerator is specifically designed for dictionary collections and provides access to both the Key and Value properties of each element during enumeration. Syntax Following is the syntax for getting an IDictionaryEnumerator from an OrderedDictionary − IDictionaryEnumerator enumerator = orderedDictionary.GetEnumerator(); Following is the syntax for iterating through the enumerator − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Return Value The GetEnumerator()
To get the types nested within the current Type in C#, you can use the GetNestedTypes() method. This method returns an array of Type objects representing all nested types (classes, interfaces, structs, etc.) defined within a type. Syntax Following is the syntax for getting nested types − Type[] nestedTypes = type.GetNestedTypes(); To specify visibility, use the overload with BindingFlags − Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic); Using GetNestedTypes() Method The GetNestedTypes() method retrieves all public nested types by default. Here's a basic example − Example using ... Read More
In ASP.NET Web API, action methods are public methods in a controller that handle HTTP requests. By default, Web API maps action methods based on HTTP verbs (GET, POST, PUT, DELETE) or method names. However, you can assign alias names to action methods using the [ActionName] attribute, providing more descriptive and meaningful URLs. Syntax Following is the syntax for using the [ActionName] attribute − [ActionName("AliasName")] public IHttpActionResult MethodName() { // method implementation } Default Action Method Naming Without aliases, Web API maps methods based on HTTP verbs or conventional ... Read More
The Stack collection in C# follows the Last In, First Out (LIFO) principle. To get the object at the top of the stack without removing it, we use the Peek() method. This method returns the top element but keeps it in the stack, unlike Pop() which removes the element. Syntax Following is the syntax for the Peek() method − public T Peek() Return Value The Peek() method returns the object at the top of the stack of type T. It throws an InvalidOperationException if the stack is empty. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance