AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 187 of 840

Stack.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 376 Views

The Stack.Equals() method in C# is used to check whether a Stack class object is equal to another object or not. This method performs reference equality, not content equality, meaning it returns true only if both variables reference the same Stack object in memory. Syntax Following is the syntax for the Stack.Equals() method − public virtual bool Equals(object obj); Parameters obj − The object to compare with the current Stack instance. Return Value Returns true if the specified object is the same instance as the current Stack; otherwise, false. ...

Read More

Difference Between Delegates and Events in C#

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

In C#, both delegates and events are used for callback mechanisms, but they serve different purposes and have distinct characteristics. Understanding their differences is crucial for proper C# programming and design patterns. Delegates A delegate is a type that represents references to methods with a specific signature. It acts as a function pointer that can hold references to one or more methods during runtime. Syntax public delegate returnType DelegateName(parameters); Example using System; public delegate void MyDelegate(string message); public class DelegateExample { public static void Method1(string ...

Read More

Stack.GetEnumerator() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 162 Views

The Stack.GetEnumerator() method in C# returns an IEnumerator that allows you to iterate through the elements of a Stack collection. This method provides a way to manually control the iteration process using the enumerator pattern, as an alternative to using foreach loops. Syntax Following is the syntax for the GetEnumerator() method − public virtual System.Collections.IEnumerator GetEnumerator(); Return Value The method returns an IEnumerator object that can be used to iterate through the Stack elements. The enumerator starts before the first element and advances using MoveNext(), with the current element accessed via the Current ...

Read More

Get an enumerator that iterates through Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 162 Views

To get an enumerator that iterates through a Collection in C#, you use the GetEnumerator() method. An enumerator provides a way to iterate through collection elements one by one using MoveNext() and Current properties. The Collection class is part of the System.Collections.ObjectModel namespace and provides a generic collection that can be customized by inheritance. Syntax Following is the syntax for getting and using an enumerator − var enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { // Access current element using enumerator.Current } How It Works GetEnumerator() returns an IEnumerator ...

Read More

Check the HybridDictionary for a specific key in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 170 Views

The HybridDictionary class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, otherwise false. HybridDictionary is part of the System.Collections.Specialized namespace and automatically switches between a ListDictionary and Hashtable based on the number of entries for optimal performance. Syntax Following is the syntax for checking if a key exists in HybridDictionary − public virtual bool Contains(object key) Parameters The Contains() method accepts the following parameter − key − The key to locate in the HybridDictionary. ...

Read More

TimeSpan.FromHours() Method in C#

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

The TimeSpan.FromHours() method in C# is used to create a TimeSpan object that represents a specified number of hours. This static method is accurate to the nearest millisecond and provides a convenient way to create time spans based on hour values. Syntax Following is the syntax for the TimeSpan.FromHours() method − public static TimeSpan FromHours(double value); Parameters value − A double that represents the number of hours. The value can be positive or negative and is accurate to the nearest millisecond. Return Value This method returns a ...

Read More

Get the number of elements contained in SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 152 Views

The Count property in C# is used to get the number of elements contained in a SortedList. This property returns an integer representing the total count of key-value pairs stored in the collection. Syntax Following is the syntax for using the Count property − int count = sortedList.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of elements. Return Value The Count property returns an int value representing the number of key-value pairs in the SortedList. Using Count Property ...

Read More

TimeSpan.Subtract() Method in C#

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

The TimeSpan.Subtract() method in C# returns a new TimeSpan object whose value is the difference between the current instance and the specified TimeSpan object. This method is useful for calculating time differences in applications dealing with durations and intervals. Syntax Following is the syntax for the TimeSpan.Subtract() method − public TimeSpan Subtract(TimeSpan span); Parameters span − The TimeSpan object to subtract from the current instance. Return Value Returns a new TimeSpan object that represents the time interval difference. If the subtracted value is greater than the current ...

Read More

Check whether a Hashtable contains a specific key or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 206 Views

The Hashtable class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, and false otherwise. Syntax Following is the syntax for checking if a Hashtable contains a specific key − bool result = hashtable.Contains(key); Parameters key − The key to search for in the Hashtable. This parameter is of type Object. Return Value The Contains() method returns a bool value − true if the Hashtable contains the specified ...

Read More

ListDictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 468 Views

The ListDictionary class in C# implements the IDictionary interface using a singly linked list. It is optimized for small collections and is recommended for collections that typically contain fewer than 10 items. For larger collections, it's better to use Hashtable or Dictionary for better performance. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dict = new ListDictionary(); dict.Add(key, value); Key Properties Property Description Count Gets the number of key/value pairs contained in the ListDictionary. IsFixedSize Gets a value indicating whether the ...

Read More
Showing 1861–1870 of 8,392 articles
« Prev 1 185 186 187 188 189 840 Next »
Advertisements