Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 710 of 2547
How to remove element from the specified index of the List in C#?
To remove an element from a specified index in a List in C#, you use the RemoveAt() method. This method removes the element at the given index and automatically shifts all subsequent elements one position to the left. Syntax Following is the syntax for the RemoveAt() method − list.RemoveAt(int index); Parameters index − The zero-based index of the element to remove. Must be a valid index (0 ≤ index < Count). Using RemoveAt() with String List The following example demonstrates removing an element at index 5 from a list ...
Read MoreHow to get Synchronize access to an Array in C#?
To get synchronized access to an array in C#, you can use the SyncRoot property of the array along with the lock statement. This ensures thread-safe access when multiple threads are accessing the same array concurrently. The SyncRoot property returns an object that can be used to synchronize access to the array, preventing data races and ensuring thread safety in multi-threaded applications. Syntax Following is the syntax for synchronizing access to an array − lock(array.SyncRoot) { // Thread-safe operations on the array foreach (var item in array) { ...
Read MoreHow to get Seventh Element of the Tuple in C#?
A Tuple in C# is a data structure that can hold multiple values of different types. To access the seventh element of a tuple, you use the Item7 property. This property is available in tuples that have seven or more elements. Syntax Following is the syntax for accessing the seventh element of a tuple − var seventhElement = tupleName.Item7; For creating a tuple with seven elements − var tuple = Tuple.Create(item1, item2, item3, item4, item5, item6, item7); Using Item7 Property The Item7 property directly retrieves the seventh element from ...
Read MoreHow to retrieve the system's reference to the specified String in C#?
The string.Intern() method in C# retrieves the system's reference to the specified string from the intern pool. The intern pool is a table maintained by the .NET runtime that contains references to all string literals and interned strings to optimize memory usage by ensuring that identical strings share the same memory location. Syntax Following is the syntax for the string.Intern() method − public static string Intern(string str) Parameters str − The string to search for in the intern pool. Return Value Returns a reference to the string ...
Read MoreRemove from the specified index of the StringCollection in C#
The StringCollection class in C# provides the RemoveAt() method to remove an element from a specified index. This method removes the string at the given index and shifts all subsequent elements one position to the left. Syntax Following is the syntax for the RemoveAt() method − stringCollection.RemoveAt(int index); Parameters index − The zero-based index of the element to remove from the StringCollection. Using RemoveAt() to Remove Single Element The following example demonstrates removing an element from a specific index in a StringCollection − using System; ...
Read MoreHybridDictionary Class in C#?
The HybridDictionary class implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large. This provides optimal performance for both small and large collections by leveraging the strengths of each underlying data structure. The HybridDictionary automatically switches from ListDictionary to Hashtable when the number of elements exceeds a certain threshold (typically around 10 items), making it ideal for scenarios where the collection size is unpredictable. HybridDictionary Internal Structure Small Collection ListDictionary Linear search ...
Read MoreGet or set the value associated with the specified key in StringDictionary in C#
The StringDictionary class in C# provides an indexer that allows you to get or set values associated with specified keys. This indexer uses the key as a parameter and returns or assigns the corresponding value. The StringDictionary is case-insensitive and specifically designed for string keys and values. Syntax Following is the syntax for the StringDictionary indexer − public virtual string this[string key] { get; set; } To get a value − string value = stringDictionary[key]; To set a value − stringDictionary[key] = value; Parameters ...
Read MoreGet the number of strings in StringCollection in C#
The StringCollection class in C# provides a specialized collection for storing strings. To get the number of strings in a StringCollection, use the Count property, which returns an integer representing the total number of elements in the collection. Syntax Following is the syntax for accessing the Count property − int count = stringCollection.Count; Using Count Property with Basic StringCollection Example using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol = new StringCollection(); ...
Read MoreCheck if Caps Lock and Num Lock is on or off through Console in C#
The C# Console class provides built-in properties to check the status of the Caps Lock and Num Lock keys. The Console.CapsLock and Console.NumberLock properties return a boolean value indicating whether these keys are currently active. Syntax Following is the syntax to check Caps Lock status − bool capsLockStatus = Console.CapsLock; Following is the syntax to check Num Lock status − bool numLockStatus = Console.NumberLock; Return Value Console.CapsLock returns true if Caps Lock is on, false otherwise. Console.NumberLock returns true if Num Lock is on, false otherwise. ...
Read MoreRemove the element with the specified key from a SortedList in C#
The SortedList class in C# provides the Remove() method to remove an element with a specified key. When you remove an element, the SortedList automatically adjusts its internal structure to maintain the sorted order of the remaining elements. Syntax Following is the syntax for removing an element from a SortedList − sortedList.Remove(key); Parameters key: The key of the element to remove from the SortedList. Using Remove() with String Keys This example demonstrates removing an element with a string key from a SortedList − using System; ...
Read More