Articles on Trending Technologies

Technical articles with clear explanations and examples

Get the handle for the Type of a specified object C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 334 Views

To get the handle for the Type of a specified object in C#, you use the Type.GetTypeHandle() method. This method returns a RuntimeTypeHandle structure that represents the type handle, which is a unique identifier for the type in the runtime environment. A type handle is useful for low-level operations and provides a lightweight way to reference types without keeping the full Type object in memory. Syntax Following is the syntax for getting a type handle − RuntimeTypeHandle handle = Type.GetTypeHandle(objectInstance); To convert back from handle to Type − Type type = ...

Read More

Get a collection of values in the StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 216 Views

The StringDictionary class in C# provides a collection that maps strings to strings, where keys are case-insensitive. To retrieve values from a StringDictionary, you can access the Values property or iterate through key-value pairs to extract the values. StringDictionary automatically converts all keys to lowercase, making it useful for scenarios where case-insensitive string lookups are required. Syntax Following is the syntax to access values in a StringDictionary − StringDictionary stringDict = new StringDictionary(); ICollection values = stringDict.Values; string value = stringDict[key]; Using Values Property The Values property returns an ICollection containing all ...

Read More

Get the fields of the current Type in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 397 Views

To get the fields of the current Type in C#, you can use the GetFields() method from the System.Reflection namespace. This method allows you to retrieve field information using various BindingFlags to specify which types of fields to include. Reflection in C# provides the ability to inspect and manipulate types, methods, properties, and fields at runtime. The Type.GetFields() method is particularly useful for examining the internal structure of classes. Syntax Following is the basic syntax for getting fields using reflection − Type type = typeof(ClassName); FieldInfo[] fields = type.GetFields(); To get specific types ...

Read More

C# Program to check if a path is a directory or a file

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 5K+ Views

In C# programming, determining whether a given path points to a directory or a file is a common task. A directory (also called a folder) is a container that organizes files and other directories on your computer. A file is a collection of data stored with a unique name and path. The .NET framework provides built-in methods in the System.IO namespace to check path types efficiently using File.Exists() and Directory.Exists() methods. Syntax Following is the syntax for checking file existence − public static bool File.Exists(string path); Following is the syntax for checking directory ...

Read More

C# program to find first set bit

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

In this problem, we are given a number n, and we need to find the position of the first set bit (1-bit) in its binary representation. The position is counted from the right, starting at 1. In this article, we are going to discuss different approaches to solving this problem using C#. Finding First Set Bit Position Number: 18 Binary: 1 0 0 1 0 ...

Read More

Check if two ArrayList objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 498 Views

Checking if two ArrayList objects are equal in C# involves understanding how the Equals() method works. The ArrayList.Equals() method checks for reference equality, not content equality. This means it only returns true if both variables point to the same object in memory. Understanding ArrayList.Equals() Behavior The Equals()

Read More

Add element to HashSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 456 Views

The HashSet in C# is a collection that stores unique elements without duplicates. To add elements to a HashSet, you use the Add() method, which returns a boolean value indicating whether the element was successfully added. Syntax Following is the syntax for adding an element to a HashSet − bool result = hashSet.Add(element); Return Value The Add() returns − true if the element was added successfully false if the element already exists in the HashSet Using Add() Method with String HashSet Here's how to ...

Read More

How to find the unique triplet that is close to the given target using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 358 Views

The Three Sum Closest problem asks us to find a triplet of numbers in an array whose sum is closest to a given target value. This problem uses the Two Pointers pattern and is similar to the Triplet Sum to Zero problem. We iterate through the array, taking one number at a time as the first element of our triplet. For each fixed element, we use two pointers to find the best pair that makes the triplet sum closest to the target. At every step, we save the difference between the triplet sum and the target, comparing it with ...

Read More

Check if a SortedSet is a subset of the specified collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 194 Views

The SortedSet class in C# provides the IsSubsetOf() method to check if all elements of one SortedSet are contained within another collection. A subset means that every element in the first set exists in the second set, though the second set may contain additional elements. Syntax Following is the syntax for the IsSubsetOf() method − public bool IsSubsetOf(IEnumerable other) Parameters other − The collection to compare with the current SortedSet. Return Value Returns true if the current SortedSet is a subset of the specified collection; otherwise, false. ...

Read More

How to find all the unique quadruplets that is close to zero using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 370 Views

Finding all unique quadruplets that sum to zero in C# is a classic algorithmic problem known as the 4Sum problem. The goal is to find all combinations of four distinct elements from an array whose sum equals zero, avoiding duplicate quadruplets. Problem Approaches There are multiple approaches to solve this problem, each with different time and space complexities − Approach Time Complexity Space Complexity Description Brute Force O(n4) O(1) Four nested loops checking all combinations HashSet Optimization O(n3) O(n) Use HashSet to find fourth element Two ...

Read More
Showing 9581–9590 of 61,299 articles
« Prev 1 957 958 959 960 961 6130 Next »
Advertisements