Csharp Articles

Page 41 of 196

Gets or sets the element at the specified index in StringCollection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 148 Views

The StringCollection class in C# provides an indexer property that allows you to get or set elements at a specified index. This indexer uses square bracket notation and provides direct access to collection elements by their zero-based index position. Syntax Following is the syntax for accessing elements by index in StringCollection − // Getting an element string element = stringCollection[index]; // Setting an element stringCollection[index] = "new value"; Parameters index − The zero-based index of the element to get or set. Return Value Returns the string ...

Read More

Gets or Sets the element at the specified index in the List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 211 Views

In C#, you can get or set elements at a specific index in a List using the indexer property. This allows you to access and modify list elements using square bracket notation, similar to arrays. Syntax Following is the syntax for accessing elements by index − // Getting an element T element = list[index]; // Setting an element list[index] = value; Getting Elements by Index The following example demonstrates how to retrieve elements from a List using their index positions − using System; using System.Collections.Generic; public class Demo { ...

Read More

Get the number of elements contained in Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 181 Views

The Count property in C# provides a simple way to determine the number of elements contained in a Collection. This property is available for all collection types that implement the ICollection interface and returns an integer value representing the current element count. Syntax Following is the syntax for using the Count property − Collection collection = new Collection(); int count = collection.Count; Using Count with String Collection The following example demonstrates how to get the count of elements in a string collection − using System; using System.Collections.ObjectModel; public class Demo ...

Read More

Removing all the elements from the List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 234 Views

The Clear() method in C# is used to remove all elements from a List. This method provides an efficient way to empty a list without having to remove elements one by one. After calling Clear(), the list's Count becomes zero, but the list object itself remains available for further operations. Syntax Following is the syntax for the Clear() method − list.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It has a void return type. Using Clear() Method ...

Read More

Remove all the strings from the StringCollection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 182 Views

The StringCollection class in C# provides the Clear() method to remove all strings from the collection at once. This method is part of the System.Collections.Specialized namespace and is useful when you need to empty the entire collection efficiently. Syntax Following is the syntax for the Clear() method − stringCollection.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It has a return type of void. StringCollection.Clear() Process Before Clear() ...

Read More

Gets or sets the value at the specified key in StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 161 Views

The StringDictionary class in C# provides an indexer property that allows you to get or set values using a key-based approach. This indexer uses the syntax dictionary[key] to access or modify values at the specified key. Syntax Following is the syntax for getting or setting values using the indexer − // Getting a value string value = stringDictionary[key]; // Setting a value stringDictionary[key] = newValue; Parameters key − A string that represents the key to locate in the StringDictionary. value − The string value to associate with the specified key when ...

Read More

Gets or sets the value in HybridDictionary with specified key in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 194 Views

The HybridDictionary class in C# provides an indexer property that allows you to get or set values using a specified key. The HybridDictionary is part of the System.Collections.Specialized namespace and combines the benefits of both ListDictionary and Hashtable for optimal performance with small and large collections. Syntax Following is the syntax for getting or setting values in HybridDictionary using the indexer − // Getting a value object value = hybridDict[key]; // Setting a value hybridDict[key] = value; Parameters key − The key of the element to get or set. Can ...

Read More

Get the type referenced by the specified type handle in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 286 Views

To get the type referenced by the specified type handle in C#, you use the Type.GetTypeFromHandle() method. This method takes a RuntimeTypeHandle and returns the corresponding Type object. Type handles provide a lightweight way to represent types at runtime and are commonly used in low-level reflection scenarios. Syntax Following is the syntax for getting a type handle and retrieving the type − RuntimeTypeHandle typeHandle = Type.GetTypeHandle(object); Type type = Type.GetTypeFromHandle(typeHandle); Parameters handle − The RuntimeTypeHandle structure that refers to the type. Return Value Returns the Type referenced by the ...

Read More

How to create a StringDictionary in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 146 Views

The StringDictionary in C# is a specialized collection class from the System.Collections.Specialized namespace that stores key-value pairs where both keys and values are strings. It's important to note that StringDictionary is case-insensitive and automatically converts all keys to lowercase. Note: StringDictionary is considered legacy and is generally replaced by Dictionary in modern C# applications. However, understanding StringDictionary is useful for maintaining older codebases. Syntax Following is the syntax for creating and using a StringDictionary − StringDictionary stringDict = new StringDictionary(); stringDict.Add("key", "value"); string value = stringDict["key"]; StringDictionary Key Conversion ...

Read More

How to find the length of the StringBuilder in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 336 Views

The StringBuilder class in C# provides the Length property to determine the number of characters currently stored in the StringBuilder object. This property is essential for string manipulation operations and memory management. Syntax Following is the syntax to get the length of a StringBuilder − int length = stringBuilder.Length; Understanding Length vs Capacity It's important to distinguish between Length and Capacity of a StringBuilder − Property Description Length Number of characters currently stored in the StringBuilder Capacity Maximum number of characters the StringBuilder ...

Read More
Showing 401–410 of 1,951 articles
« Prev 1 39 40 41 42 43 196 Next »
Advertisements