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 8 of 2547
How do I overload the [] operator in C#?
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 MoreHow to check whether the given strings are isomorphic using C#?
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 MoreRemove all elements of a List that match the conditions defined by the predicate in C#
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 MoreCheck if OrderedDictionary collection contains a specific key in C#
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 MoreHow to Deserializing JSON to .NET object using Newtonsoft json in C# and pick only one value from the array?
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 MoreHow to find the length of the longest substring from the given string without repeating the characters using C#?
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 MoreCheck if two LinkedList objects are equal in C#
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 MoreConvert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#
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 MoreC# Program to Delete Empty and Nonempty Directory
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 MoreHow to find the length of the longest continuous increasing subsequence from an array of numbers using C#?
The Longest Continuous Increasing Subsequence problem finds the length of the longest subarray where elements are in strictly increasing order. This algorithm uses a single pass through the array to track the current sequence length and maintains the maximum length found so far. The approach uses two variables: count to track the current increasing sequence length and res to store the maximum length encountered. When an element breaks the increasing pattern, the count resets to 1. Algorithm Explanation The algorithm works as follows − Initialize count = 1 and res = 1 to handle ...
Read More