Programming Articles

Page 724 of 2547

Insert at the specified index in StringCollection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 211 Views

The StringCollection class in C# provides the Insert() method to add elements at specific positions within the collection. This method shifts existing elements to the right to make room for the new element at the specified index. Syntax Following is the syntax for the Insert() method − stringCollection.Insert(index, value); Parameters index − The zero-based index at which to insert the element. value − The string value to insert into the collection. Using Insert() Method Example using System; using System.Collections.Specialized; public class Demo { ...

Read More

How to check whether a thread is a background thread or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 275 Views

In C#, you can check whether a thread is a background thread using the IsBackground property of the Thread class. Background threads are automatically terminated when all foreground threads complete, while foreground threads keep the application running until they finish execution. Syntax Following is the syntax to check if a thread is a background thread − bool isBackground = thread.IsBackground; To set a thread as a background thread − thread.IsBackground = true; Understanding Background vs Foreground Threads Background vs Foreground Threads ...

Read More

How to Add Items to Hashtable Collection in C#

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

A Hashtable collection in C# stores key-value pairs using a hash-based mechanism. Each key-value pair is organized based on the hash code of the key, which is calculated using a hash function. Unlike modern generic collections, hashtables can store objects of different data types but exhibit lower performance due to boxing and unboxing operations. In this article, we will explore how to add items to a hashtable collection using various methods available in the Hashtable class. Syntax The primary method for adding items to a hashtable is the Add() method − public virtual void Add(object ...

Read More

Decimal Struct in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 490 Views

The Decimal struct in C# represents a high-precision decimal floating-point number ideal for financial and monetary calculations. The Decimal value type represents decimal numbers ranging from positive 79, 228, 162, 514, 264, 337, 593, 543, 950, 335 to negative 79, 228, 162, 514, 264, 337, 593, 543, 950, 335. The default value of a Decimal is 0. The Decimal struct provides better precision than float or double for calculations where exact decimal representation is crucial, such as currency operations. Decimal vs Float Precision Comparison Decimal 0.1 + ...

Read More

SortedDictionary.ContainsValue() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 134 Views

The SortedDictionary.ContainsValue() method in C# is used to determine whether the SortedDictionary contains an element with the specified value. This method performs a linear search through all values in the collection. Syntax Following is the syntax of the ContainsValue() method − public bool ContainsValue(TValue value) Parameters value − The value to be searched in the SortedDictionary. The value can be null for reference types. Return Value Returns true if the SortedDictionary contains an element with the specified value; otherwise, false. Using ContainsValue() to Check Existing Values The following example ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 160 Views

In C#, you can access the fifth element of a tuple using the Item5 property. This property is available for tuples that contain at least five elements. The Item5 property returns the value stored at the fifth position in the tuple. Syntax Following is the syntax to access the fifth element of a tuple − var fifthElement = tupleVariable.Item5; Where tupleVariable is a tuple with at least five elements, and Item5 retrieves the value at the fifth position. Using Item5 Property Example 1 The following example demonstrates how to access the ...

Read More

Insert into OrderedDictionary with key and value at specified index in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 420 Views

The OrderedDictionary class in C# provides an Insert() method to add key-value pairs at a specific index position. Unlike regular dictionaries, OrderedDictionary maintains the insertion order of elements and allows indexed access. Syntax Following is the syntax for inserting into an OrderedDictionary at a specified index − orderedDict.Insert(index, key, value); Parameters index − The zero-based index at which to insert the key-value pair key − The key of the element to insert value − The value of the element to insert Using Insert() Method The following example demonstrates inserting ...

Read More

How to convert IEnumerable to List and List back to IEnumerable in C#?

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

IEnumerable is an interface that defines a single method GetEnumerator() and provides the foundation for iterating over collections. The List class is a concrete implementation that provides indexed access and manipulation methods for collections. Converting between these types is a common requirement in C# development. IEnumerable offers read-only iteration, while List provides full collection manipulation capabilities including adding, removing, and sorting elements. Converting IEnumerable to List The most efficient way to convert IEnumerable to List is using the ToList() extension method − Using ToList() Method using System; using System.Collections.Generic; using System.Linq; class Program ...

Read More

Console Class in C#

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

The Console class in C# is part of the System namespace and provides methods and properties for interacting with the console window. It handles standard input, output, and error streams for console applications, allowing you to control cursor position, colors, buffer size, and other console characteristics. Syntax The Console class provides static properties and methods. Here are the basic syntax patterns − Console.PropertyName = value; // Setting properties var value = Console.PropertyName; // Getting properties Console.MethodName(parameters); // Calling methods ...

Read More

Queue.Enqueue() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 486 Views

The Queue.Enqueue() method in C# is used to add an object to the end of the Queue. This method follows the FIFO (First In, First Out) principle where elements are added at the rear and removed from the front. Syntax For generic Queue collections − public void Enqueue(T item); For non-generic Queue collections − public virtual void Enqueue(object obj); Parameters item/obj − The object to add to the end of the Queue. The value can be null for reference types. Queue.Enqueue() Operation ...

Read More
Showing 7231–7240 of 25,466 articles
« Prev 1 722 723 724 725 726 2547 Next »
Advertisements