Get the hash code for this instance in C#

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

296 Views

To get the hash code for this instance in C#, you use the GetHashCode() method. This method returns a hash code for the current object, which is useful for hash-based operations and collections like HashSet and Dictionary. Syntax Following is the syntax for getting the hash code of an instance − public virtual int GetHashCode() Return Value The GetHashCode() method returns a 32-bit signed integer that serves as the hash code for this instance. Objects that are equal should return the same hash code, though the reverse is not necessarily true. Using ... Read More

How do I overload the [] operator in C#?

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

396 Views

The indexer ([] operator) in C# allows an object to be accessed like an array using square bracket notation. When you define an indexer for a class, instances of that class behave like virtual arrays, enabling array-style access using the [] operator. Indexers can be overloaded with different parameter types and counts. The parameters don't have to be integers — you can use strings, multiple parameters, or any other type as the index. Syntax Following is the basic syntax for defining an indexer − public returnType this[indexType index] { get { ... Read More

How to check whether the given strings are isomorphic using C#?

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

1K+ Views

Two strings are called isomorphic if there exists a one-to-one character mapping between them. This means each character in the first string maps to exactly one character in the second string, and no two characters can map to the same character. The mapping must be consistent throughout both strings. For example, "egg" and "add" are isomorphic because 'e' maps to 'a', and 'g' maps to 'd'. However, "foo" and "bar" are not isomorphic because 'o' would need to map to both 'a' and 'r'. Algorithm Approach The solution uses two arrays to track the last seen position ... Read More

Remove all elements of a List that match the conditions defined by the predicate in C#

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

1K+ Views

The RemoveAll() method in C# removes all elements from a List that match the conditions defined by a predicate. A predicate is a method that takes an element as input and returns a boolean value indicating whether the element should be removed. Syntax Following is the syntax for the RemoveAll() method − public int RemoveAll(Predicate match) Parameters match − A predicate delegate that defines the conditions for removal. It takes an element of type T and returns true if the element should be removed. Return Value The method returns ... Read More

Check if OrderedDictionary collection contains a specific key in C#

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

241 Views

The OrderedDictionary collection in C# provides the Contains() method to check if a specific key exists in the collection. This method returns a boolean value − true if the key is found, false otherwise. Syntax Following is the syntax for checking if an OrderedDictionary contains a specific key − bool result = orderedDictionary.Contains(key); Parameters key − The key to locate in the OrderedDictionary collection. Return Value The method returns true if the OrderedDictionary contains an element with the specified key; otherwise, false. Using Contains() with Numeric Keys ... Read More

How to Deserializing JSON to .NET object using Newtonsoft json in C# and pick only one value from the array?

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

654 Views

JSON deserialization is the process of converting JSON data into .NET objects. The Newtonsoft.Json library (also known as Json.NET) provides powerful methods to deserialize JSON strings into strongly-typed C# objects. When working with JSON arrays, you can easily pick specific values from the deserialized array. Syntax Following is the syntax for deserializing JSON to a .NET object − T obj = JsonConvert.DeserializeObject(jsonString); For deserializing JSON arrays − T[] objArray = JsonConvert.DeserializeObject(jsonString); Using WebClient to Fetch and Deserialize JSON The WebClient class provides methods for downloading data from web resources. ... Read More

How to find the length of the longest substring from the given string without repeating the characters using C#?

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

1K+ Views

The longest substring without repeating characters problem can be efficiently solved using the sliding window technique with two pointers. This approach maintains a window of unique characters and expands or contracts it based on whether duplicates are found. Algorithm Overview The sliding window technique uses two pointers i (left) and j (right) to maintain a window of unique characters. When a duplicate character is encountered, the left pointer moves forward to exclude the duplicate, while the right pointer continues expanding the window. Sliding Window Technique ... Read More

Check if two LinkedList objects are equal in C#

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

181 Views

To check if two LinkedList objects are equal in C#, you need to understand that the Equals() method performs reference equality by default, not content equality. This means it only returns true if both references point to the same object instance. Understanding Reference vs Content Equality The LinkedList class inherits the default Equals() method from Object, which compares object references rather than the actual contents of the lists. LinkedList Equality Types Reference Equality list1.Equals(list2) Returns true only if both ... Read More

Convert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#

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

283 Views

The Decimal.ToUInt16() method in C# converts a decimal value to its equivalent 16-bit unsigned integer (ushort). This method performs truncation, discarding the fractional part and keeping only the integer portion of the decimal value. Syntax Following is the syntax for the Decimal.ToUInt16() method − public static ushort ToUInt16(decimal value) Parameters value − The decimal number to be converted to a 16-bit unsigned integer. Return Value Returns a ushort (16-bit unsigned integer) that represents the truncated value of the specified decimal. The valid range is 0 to 65, ... Read More

C# Program to Delete Empty and Nonempty Directory

Ankit kumar
Updated on 17-Mar-2026 07:04:36

802 Views

In C#, directories (folders) are used to organize files and other directories on the computer. The Directory class provides static methods for managing directories, while DirectoryInfo provides instance methods for working with specific directories. This article demonstrates how to delete both empty and non-empty directories using C#. Syntax The Directory.Delete() method has two overloads for deleting directories − public static void Delete(string path); public static void Delete(string path, bool recursive); Parameters path − The directory path to delete (string type) recursive − true to delete subdirectories and files; false ... Read More

Advertisements