Programming Articles

Page 726 of 2547

Stack.Clone() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 308 Views

The Stack.Clone() method in C# creates a shallow copy of the Stack. This method returns a new Stack object with the same elements as the original, but both stacks remain independent for basic operations like Push and Pop. Syntax Following is the syntax for the Stack.Clone() method − public virtual object Clone(); Return Value The method returns an object that represents a shallow copy of the Stack. You need to cast it back to a Stack type to use it as a Stack. Understanding Shallow Copy A shallow copy means that ...

Read More

Check if two ListDictionary objects are equal in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 209 Views

The ListDictionary class in C# is part of the System.Collections.Specialized namespace and provides a simple list-based dictionary implementation. To check if two ListDictionary objects are equal, you can use the Equals() method, which performs reference equality comparison by default. Syntax Following is the syntax for comparing two ListDictionary objects − bool isEqual = listDict1.Equals(listDict2); Understanding ListDictionary Equality The Equals() method in ListDictionary performs reference equality, not content equality. This means it returns true only when both variables refer to the same object in memory, not when they contain the same key-value pairs. ...

Read More

Check if every List element matches the predicate conditions in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 420 Views

To check if every List element matches the predicate conditions in C#, you can use the List.TrueForAll() method. This method takes a predicate delegate and returns true if all elements in the list satisfy the condition, or false if any element fails the test. Syntax Following is the syntax for the TrueForAll() method − public bool TrueForAll(Predicate match) Parameters match: A delegate that defines the conditions to check against the elements. It takes an element of type T and returns a boolean. Return Value Returns true if every element ...

Read More

Number of elements contained in the BitArray in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 139 Views

The Count property in C# is used to get the number of elements contained in a BitArray. This property returns an integer value representing the total number of bits in the BitArray, regardless of their values (true or false). Syntax Following is the syntax for accessing the Count property − int count = bitArray.Count; Return Value The Count property returns an int value representing the total number of elements (bits) in the BitArray. Using Count Property with BitArray Operations The following example demonstrates how to use the Count property with BitArray ...

Read More

How to Check if a Key Exists in the Hashtable in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 2K+ Views

The Hashtable class in C# represents a collection of key-value pairs organized based on the hash code of each key. In hashtables, keys are unique and non-null, while values can be null or duplicated. Often, you need to verify whether a specific key exists before performing operations like retrieval or updates. C# provides two methods to check if a key exists in a hashtable: ContainsKey() and Contains(). Both methods serve the same purpose but have slightly different naming conventions for clarity. Syntax Following is the syntax for the ContainsKey() method − public virtual bool ContainsKey(object ...

Read More

How to get all the directories and sub directories inside a path in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 26K+ Views

To get directories in C#, the Directory.GetDirectories method is used. This method returns the names of subdirectories (including their full paths) that match a specified search pattern in a given directory, with options to search subdirectories recursively. The method allows you to control the search scope using SearchOption enumeration values. The wildcard pattern * matches zero or more characters, enabling flexible directory matching. Syntax Following is the basic syntax for Directory.GetDirectories method − string[] Directory.GetDirectories(string path, string searchPattern, SearchOption searchOption) Parameters path − The relative or absolute path to the directory ...

Read More

Console.Read() Method in C#

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

The Console.Read() method in C# reads a single character from the standard input stream and returns its ASCII value as an integer. Unlike Console.ReadLine() which reads entire lines, Console.Read() processes one character at a time. Syntax Following is the syntax for the Console.Read() method − public static int Read(); Return Value The method returns an int representing the ASCII value of the character read, or -1 if no more characters are available. Using Console.Read() to Get Character ASCII Values Example using System; public class Demo { ...

Read More

Queue.Synchronized() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 256 Views

The Queue.Synchronized() method in C# returns a thread-safe wrapper around an existing Queue object. This method is part of the System.Collections namespace and provides synchronization for multi-threaded applications where multiple threads need to access the same queue safely. Syntax Following is the syntax for the Queue.Synchronized() method − public static System.Collections.Queue Synchronized(System.Collections.Queue queue); Parameters The method accepts one parameter − queue − The Queue object to be wrapped with synchronization. Return Value Returns a synchronized (thread-safe) wrapper for the specified Queue. The wrapper provides synchronized access to all ...

Read More

How to get First Element of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 961 Views

A tuple in C# is a data structure that can hold multiple values of different types. To get the first element of a tuple, you use the Item1 property, which provides direct access to the first value stored in the tuple. Syntax Following is the syntax for accessing the first element of a tuple − var tuple = Tuple.Create(value1, value2, value3, ...); var firstElement = tuple.Item1; For value tuples (C# 7.0+), you can also use named elements − var tuple = (first: value1, second: value2, third: value3); var firstElement = tuple.first; ...

Read More

How to create a ListDictionary in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 146 Views

A ListDictionary in C# is a specialized collection class from the System.Collections.Specialized namespace that implements IDictionary using a singly linked list. It is optimized for small collections (typically 10 items or fewer) and offers better performance than Hashtable for small datasets. The ListDictionary class is ideal when you need a dictionary-like collection with a small number of elements, as it has lower memory overhead compared to hash-based collections. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dictionary = new ListDictionary(); To add key-value pairs to the ListDictionary − ...

Read More
Showing 7251–7260 of 25,466 articles
« Prev 1 724 725 726 727 728 2547 Next »
Advertisements