AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 168 of 840

How to create an OrderedDictionary in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 161 Views

An OrderedDictionary in C# is a specialized collection that maintains the insertion order of key-value pairs. Unlike a regular Dictionary, it preserves the sequence in which elements were added, making it useful when order matters. The OrderedDictionary class is part of the System.Collections.Specialized namespace and provides both indexed access and key-based access to elements. Syntax Following is the syntax for creating an OrderedDictionary − OrderedDictionary dict = new OrderedDictionary(); dict.Add(key, value); dict[index] = value; // Access by index dict[key] = value; // Access by key Creating and Populating an ...

Read More

Queue.IsSynchronized Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 161 Views

The Queue.IsSynchronized property in C# is used to determine whether access to the Queue is synchronized, meaning it is thread-safe for concurrent access by multiple threads. Syntax Following is the syntax for the IsSynchronized property − public virtual bool IsSynchronized { get; } Return Value The property returns a bool value − true − if access to the Queue is synchronized (thread-safe) false − if access to the Queue is not synchronized Using IsSynchronized with Regular Queue By default, a regular Queue is not synchronized and returns false ...

Read More

Queue.Peek Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 482 Views

The Queue.Peek() method in C# is used to return the object at the beginning of the Queue without removing it. This method is useful when you need to examine the first element in the queue without modifying the queue's contents. Syntax Following is the syntax for the non-generic Queue − public virtual object Peek(); Following is the syntax for the generic Queue − public T Peek(); Return Value The method returns the object at the beginning of the Queue. For generic queues, it returns type T, and for non-generic ...

Read More

Total number of elements present in an array in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 260 Views

In C#, you can get the total number of elements present in an array using several different approaches. The most common methods are using the Length property, GetLength() method, or LongLength property for very large arrays. Syntax Following are the different ways to get array length − // Using Length property (most common) int count = arrayName.Length; // Using GetLength() method for specific dimension int count = arrayName.GetLength(0); // Using LongLength for very large arrays long count = arrayName.LongLength; Using Length Property The Length property is the most commonly used approach ...

Read More

Single.IsNaN() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 244 Views

The Single.IsNaN() method in C# is used to determine whether a specified float value is not a number (NaN). This method returns true if the value is NaN, and false otherwise. NaN typically results from undefined mathematical operations like dividing zero by zero. Syntax Following is the syntax for the Single.IsNaN() method − public static bool IsNaN(float f); Parameters f − A single-precision floating-point number to be tested. Return Value Returns true if the value is NaN (Not a Number), otherwise false. ...

Read More

Stack.Synchronized() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 154 Views

The Stack.Synchronized() method in C# returns a synchronized (thread-safe) wrapper for a Stack. This wrapper ensures that all operations on the stack are thread-safe, making it suitable for use in multi-threaded applications where multiple threads might access the same stack simultaneously. Syntax Following is the syntax for the Stack.Synchronized() method − public static System.Collections.Stack Synchronized(System.Collections.Stack stack); Parameters stack − The Stack object to synchronize. Return Value Returns a synchronized wrapper for the specified Stack. The returned wrapper provides thread-safe access to all Stack operations. Stack.Synchronized() Wrapper ...

Read More

How to find the Capacity of a StringBuilder in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 175 Views

The StringBuilder class in C# provides a Capacity property that returns the current capacity of the StringBuilder instance. The capacity represents the total number of characters that the StringBuilder can hold before it needs to allocate more memory. Syntax Following is the syntax to access the Capacity property − int capacity = stringBuilder.Capacity; How StringBuilder Capacity Works StringBuilder automatically manages its internal buffer size. When you create a StringBuilder, it starts with a default capacity of 16 characters. If you exceed this capacity, StringBuilder automatically doubles the buffer size to accommodate more characters. ...

Read More

Stack.ToString() Method in C# with examples

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

The Stack.ToString() method in C# is used to get the string representation of the Stack class object. This method returns the fully qualified type name of the stack instance, not the contents of the stack. To display stack elements, you need to iterate through the collection and call ToString() on individual elements. Syntax Following is the syntax for the Stack.ToString() method − public override string ToString(); Return Value This method returns a string that represents the current Stack object. It returns the type name "System.Collections.Stack". Using ToString() on Stack Elements The ...

Read More

StringCollection Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 862 Views

The StringCollection class in C# is a specialized collection that stores strings. It is part of the System.Collections.Specialized namespace and provides methods specifically designed for string operations, making it more efficient than generic collections when working exclusively with strings. Properties Following are the key properties of the StringCollection class − Property Description Count Gets the number of strings contained in the StringCollection. IsReadOnly Gets a value indicating whether the StringCollection is read-only. IsSynchronized Gets a value indicating whether access to the StringCollection is synchronized (thread safe). ...

Read More

SByte.CompareTo() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 130 Views

The SByte.CompareTo() method in C# is used to compare the current sbyte instance to a specified object or sbyte value and returns an integer that indicates their relative ordering. This method is essential for sorting operations and comparison logic. Syntax The SByte.CompareTo() method has two overloads − public int CompareTo(sbyte value); public int CompareTo(object obj); Parameters value − An 8-bit signed integer to compare with the current instance. obj − An object to compare with the current instance, or null. Return Value The method returns ...

Read More
Showing 1671–1680 of 8,392 articles
« Prev 1 166 167 168 169 170 840 Next »
Advertisements