Programming Articles

Page 29 of 2547

Difference Between dispose() and finalize() in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

In this article, we will understand the difference between the Dispose() and Finalize() methods in C#. Both methods are used for resource cleanup, but they serve different purposes and are invoked in different ways during the object lifecycle. The Dispose() method provides deterministic cleanup where you control exactly when resources are freed, while Finalize() provides a safety net for cleanup that runs during garbage collection. Syntax Following is the syntax for implementing Dispose() method − public class MyClass : IDisposable { public void Dispose() { // ...

Read More

How to find the distinct subsets from a given array by backtracking using C#?

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

The distinct subsets problem involves finding all unique combinations of a specific size from a given array using backtracking. This technique systematically explores all possible combinations by adding elements to the current subset and then removing them to explore other possibilities. When we specify a target size, the algorithm generates all combinations that contain exactly that many elements. For example, with array [1, 2, 3] and target size 2, we get combinations "1, 2", "1, 3", and "2, 3". How Backtracking Works for Subsets The backtracking algorithm follows these steps − Choose − Add an ...

Read More

Single.Equals() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 127 Views

The Single.Equals() method in C# is used to return a value indicating whether two instances of Single represent the same value. The Single type is an alias for float in C#, so this method compares floating-point values for equality. Syntax The Single.Equals() method has two overloads − public bool Equals(float obj); public override bool Equals(object obj); Parameters obj − The object or float value to compare with the current instance. Return Value Returns true if the specified value is equal to the current instance; otherwise, false. For the object overload, it ...

Read More

Get an ICollection containing the keys in ListDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 125 Views

The ListDictionary class in C# provides a Keys property that returns an ICollection containing all the keys in the dictionary. This is useful when you need to iterate through or process only the keys without accessing their corresponding values. Syntax Following is the syntax to get the keys collection from a ListDictionary − ICollection keys = listDictionary.Keys; Return Value The Keys property returns an ICollection object that contains all the keys from the ListDictionary. The keys are returned in the same order as they were added to the dictionary. Using Keys Property ...

Read More

C# Program to Print the Length of the Hashtable

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 873 Views

A Hashtable in C# is a collection that stores key-value pairs, where each key is unique and used to access its corresponding value. Unlike arrays or lists, Hashtables don't have a direct Length property, but we can determine the number of elements using the Count property. The Hashtable class belongs to the System.Collections namespace and organizes elements based on the hash code of their keys. Keys must be unique and non-null, while values can be duplicated or null. Syntax The Count property returns the number of key-value pairs in the Hashtable − public virtual int ...

Read More

How to find the unique combination k sum that corresponds to k sum using C#?

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

The k-sum combination problem involves finding all unique combinations of exactly k numbers from a given range that sum up to a specific target value. This is solved using backtracking, which explores all possible combinations while pruning invalid paths early. The algorithm maintains two lists: an output list to store valid combinations and a currentList to track the current combination being explored. The backtracking function recursively explores combinations, adding numbers one by one until either the target sum is achieved with exactly k numbers, or the constraints are violated. How It Works The backtracking algorithm follows these ...

Read More

C# BitConverter.ToString(Byte[]) Method

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

The BitConverter.ToString() method in C# converts an array of bytes to its hexadecimal string representation. Each byte is converted to a two-digit uppercase hexadecimal value, with hyphens separating each pair. Syntax Following is the syntax for the BitConverter.ToString() method − public static string ToString(byte[] value); Parameters value − An array of bytes to convert to hexadecimal string representation. Return Value Returns a string containing hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in the byte array. Byte Array to Hex ...

Read More

Get an ICollection containing the values in HybridDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 152 Views

The HybridDictionary class in C# provides the Values property that returns an ICollection containing all the values in the dictionary. This collection can be used to iterate through values or copy them to an array for further processing. Syntax Following is the syntax to get the values collection from a HybridDictionary − ICollection values = hybridDictionary.Values; To copy values to an array − hybridDictionary.Values.CopyTo(array, startIndex); How It Works The Values property returns an ICollection that contains all the values stored in the HybridDictionary. The order of values may vary ...

Read More

Check whether a SortedList object contains a specific key in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 180 Views

To check whether a SortedList object contains a specific key in C#, you use the Contains() method. This method returns true if the key exists in the SortedList, otherwise false. A SortedList automatically maintains its elements in sorted order by key. Syntax Following is the syntax for checking if a key exists in a SortedList − bool result = sortedList.Contains(key); Parameters key: The key to search for in the SortedList. The key can be of any type that implements IComparable. Return Value The Contains() method returns a bool value ...

Read More

MathF.Cbrt() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 153 Views

The MathF.Cbrt() method in C# is used to return the cube root of a floating-point value. This method is part of the System namespace and works specifically with float data types, providing better performance than the generic Math.Cbrt() method when working with single-precision floating-point numbers. Syntax Following is the syntax − public static float Cbrt(float val); Parameters val − A floating-point number whose cube root is to be calculated. Return Value Returns a float value representing the cube root of the specified number. If the input is NaN (Not ...

Read More
Showing 281–290 of 25,467 articles
« Prev 1 27 28 29 30 31 2547 Next »
Advertisements