Programming Articles

Page 9 of 2547

Create a Stack from a collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 170 Views

To create a Stack from a collection in C#, you can use the Stack constructor that accepts an IEnumerable parameter. This allows you to initialize a stack with elements from arrays, lists, or other collections. Syntax Following is the syntax for creating a Stack from a collection − Stack stack = new Stack(IEnumerable collection); The elements are pushed in the reverse order of the collection enumeration. Creating Stack from Array The following example shows how to create a Stack from an existing array − using System; using System.Collections.Generic; public ...

Read More

Check if OrderedDictionary collection is read-only in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 150 Views

The OrderedDictionary class in C# provides a collection that maintains the order of key-value pairs while allowing access by both key and index. To check if an OrderedDictionary is read-only, you use the IsReadOnly property. An OrderedDictionary is typically not read-only by default, meaning you can add, modify, and remove elements after creation. However, you can create a read-only wrapper using specific methods. Syntax Following is the syntax to check if an OrderedDictionary is read-only − bool isReadOnly = orderedDictionary.IsReadOnly; Following is the syntax to create a read-only wrapper − OrderedDictionary ...

Read More

How to implement Fibonacci using topDown approach using C#?

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

The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The top-down approach focuses on breaking down a big problem into smaller and understandable chunks using memoization to store previously computed values. This approach uses recursion with an additional array to cache results, avoiding redundant calculations and significantly improving performance over naive recursion. Complexity Analysis Time complexity − O(N) because each Fibonacci number is ...

Read More

Adding new node or value at the start of LinkedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 220 Views

To add a new node or value at the start of a LinkedList in C#, you can use the AddFirst() method. This method adds the specified element at the beginning of the LinkedList, making it the first node. Syntax Following is the syntax for adding elements to the beginning of a LinkedList − linkedList.AddFirst(value); You can also add a LinkedListNode object − linkedList.AddFirst(new LinkedListNode(value)); Parameters The AddFirst() method accepts the following parameter − value − The value to add at the beginning of the LinkedList ...

Read More

How to use "not in" query with C# LINQ?

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

In C# LINQ, there are several ways to perform "not in" queries to exclude items from one collection that exist in another. The most common approaches use the Except operator, the Where clause with Any, or the Contains method. These operators work with any data source that implements IEnumerable, making them versatile for querying collections, arrays, and LINQ query results. Syntax Using the Except operator − var result = collection1.Except(collection2); Using Where with Any − var result = from item in collection1 ...

Read More

Creating a Case-Sensitive HybridDictionary with specified initial size in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 162 Views

The HybridDictionary class in C# is a collection that combines the benefits of both ListDictionary and Hashtable. It automatically switches from a ListDictionary (for small collections) to a Hashtable (for larger collections) based on the number of elements. You can create a case-sensitive HybridDictionary with a specified initial size using its constructor. Syntax Following is the syntax for creating a HybridDictionary with specified initial size and case sensitivity − HybridDictionary myDict = new HybridDictionary(initialSize, caseInsensitive); Parameters initialSize − The approximate number of entries that the HybridDictionary can initially contain. ...

Read More

Adding the elements of the specified collection to the end of the List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 150 Views

The AddRange() method in C# allows you to add all elements from a specified collection to the end of a List. This method is more efficient than adding elements one by one using Add() when you need to append multiple items from an existing collection. Syntax Following is the syntax for the AddRange() method − public void AddRange(IEnumerable collection) Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. Using ...

Read More

How to implement minimum step to one using topDown approach using C#?

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

The minimum steps to one problem asks: given a positive integer n, find the minimum number of steps to reduce it to 1 using these operations − If n is divisible by 3, divide it by 3 If n is divisible by 2, divide it by 2 Subtract 1 from n The top-down approach uses recursion with memoization to solve this problem efficiently by storing computed results in a DP array. How It Works The algorithm recursively explores all possible operations at each step and chooses the one that gives the minimum result. Memoization ...

Read More

Creating a HybridDictionary with specified initial size in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 142 Views

The HybridDictionary class in C# is a special collection that automatically switches between a ListDictionary for small collections and a Hashtable for larger ones. When creating a HybridDictionary with a specified initial size, you can optimize performance by indicating the expected number of elements. The HybridDictionary uses a ListDictionary when the collection is small (typically less than 10 items) and switches to a Hashtable when it grows larger, providing the best performance characteristics for both scenarios. Syntax Following is the syntax for creating a HybridDictionary with specified initial size − HybridDictionary dict = new HybridDictionary(initialSize); ...

Read More

Adding the specified key and value into HybridDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 140 Views

The HybridDictionary class in C# provides a collection that combines the functionality of a ListDictionary for small collections and a Hashtable for larger collections. It automatically switches between these internal implementations based on the number of elements to optimize performance. HybridDictionary is part of the System.Collections.Specialized namespace and uses a ListDictionary when the collection is small (typically under 10 items) and switches to a Hashtable when it grows larger. Syntax Following is the syntax for adding key-value pairs to a HybridDictionary − HybridDictionary dictionary = new HybridDictionary(); dictionary.Add(key, value); Parameters key ...

Read More
Showing 81–90 of 25,467 articles
« Prev 1 7 8 9 10 11 2547 Next »
Advertisements