A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class and provide us the opportunity to process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher. Message handlers are executed much earlier in the request processing pipeline, making them ideal for implementing cross-cutting concerns in Web API. They form a chain of classes that process HTTP requests and responses through a pipeline. ASP.NET Web API Message Handler Pipeline ... Read More
The GetHashCode() method in C# returns a 32-bit signed integer hash code for the current Decimal instance. This hash code is used internally by collections like HashSet and Dictionary to efficiently store and retrieve decimal values. Hash codes are essential for the proper functioning of hash-based collections, as they provide a quick way to categorize and locate objects. Two Decimal instances that are equal will always return the same hash code, but different decimal values may occasionally produce the same hash code (hash collision). Syntax Following is the syntax for getting the hash code of a Decimal ... Read More
Sorting a list of complex types in C# can be achieved using the Comparison delegate with the Sort() method. The List.Sort() method has an overload that accepts a Comparison delegate, allowing you to define custom sorting logic for complex objects. The Comparison delegate represents a method that compares two objects of the same type and returns an integer indicating their relative order. Syntax Following is the syntax for the Sort() method using a Comparison delegate − public void Sort(Comparison comparison) The comparison delegate signature is − public delegate int Comparison(T x, ... Read More
The String class in C# provides essential properties that allow you to access and examine string data. The two primary properties are Chars for accessing individual characters and Length for determining the string size. String Properties Following are the key properties of the String class in C# − Property Description Chars Gets the Char object at a specified position in the current String object using indexer syntax. Length Gets the number of characters in the current String object. Syntax Following is the syntax ... Read More
Both Monitor and lock provide thread synchronization mechanisms in C#, but they serve different purposes. The lock statement is a simplified syntax that internally uses Monitor.Enter and Monitor.Exit with proper exception handling. Monitor offers more advanced features for complex threading scenarios. Syntax Following is the syntax for using lock statement − lock (lockObject) { // critical section code } Following is the syntax for using Monitor class − Monitor.Enter(lockObject); try { // critical section code } finally { Monitor.Exit(lockObject); } ... Read More
C# and C++ are both powerful programming languages, but they serve different purposes and have distinct characteristics. Understanding their differences helps developers choose the right language for their projects. What is C#? C# is a general-purpose object-oriented programming language developed by Anders Hejlsberg and his team at Microsoft. It is pronounced as 'C sharp' and is considered a pure object-oriented programming language that runs on the .NET framework. Key characteristics of C# include − Automatic memory management through garbage collection Platform-specific (primarily Windows, though .NET Core enables cross-platform development) No ... Read More
The Thread.CurrentThread property in C# is used to get a reference to the currently executing thread. This static property returns the Thread object representing the thread that is currently running, allowing you to access information about the current thread's state, name, ID, and other properties. Syntax The syntax for accessing the current thread is as follows − public static System.Threading.Thread CurrentThread { get; } Return Value This property returns a Thread object that represents the currently executing thread. Through this object, you can access various thread properties and methods. Using Thread.CurrentThread for ... Read More
To convert a Decimal value to an equivalent 8-bit unsigned integer (byte), C# provides the Decimal.ToByte() method. This method truncates the decimal portion and converts the integer part to a byte value, which ranges from 0 to 255. The conversion follows banker's rounding rules for values exactly between two integers, and throws an OverflowException if the decimal value is outside the valid byte range. Syntax Following is the syntax for converting decimal to byte − byte result = Decimal.ToByte(decimalValue); Parameters decimalValue − The decimal number to convert to a byte. Must ... Read More
Retry logic is implemented to handle transient failures that may resolve themselves after a brief delay. This pattern is essential when working with network operations, database connections, or external APIs that may temporarily fail due to network issues, service overload, or temporary unavailability. It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified. Implement retry logic only where you have the full context of a failing operation and when the operation is idempotent (safe to repeat). Syntax Following is the basic syntax for ... Read More
The StringBuilder.Chars[] property in C# provides indexed access to individual characters within a StringBuilder instance. This property allows you to both get and set characters at specific positions, making it useful for character-level manipulations without converting the entire StringBuilder to a string. Syntax Following is the syntax for the StringBuilder.Chars[] property − public char this[int index] { get; set; } Parameters index − The zero-based position of the character to get or set. Must be within the bounds of the StringBuilder (0 to Length-1). Return Value Returns ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance