C# | Check if the StringCollection is read-only
StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace.
StringCollection.IsReadOnly property is used to get a value indicating whether the StringCollection is read-only or not.
Syntax:
public bool IsReadOnly { get; }
Return Value: This property always returns false.
Note:
- A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.
- Retrieving the value of this property is an O(1) operation.
Example:
// C# code to check if the // StringCollection is read-only using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] { "A", "B", "C", "D", "E" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // checking if StringCollection is // read-only Console.WriteLine(myCol.IsReadOnly); } } |
Output:
False
Reference:
Recommended Posts:
- C# | Check if the specified string is in the StringCollection
- C# | Check if two StringCollection objects are equal
- C# | Check if StringCollection is synchronized (thread safe)
- C# | StringCollection Class
- C# | Get or Set at specified index in StringCollection
- C# | Add a string to the end of the StringCollection
- How to create a StringCollection in C#
- C# | Get the number of strings in StringCollection
- C# | Remove from the specified index of the StringCollection
- C# | Index of first occurrence in StringCollection
- How to get Synchronize access to the StringCollection in C#
- C# | Insert at the specified index in StringCollection
- C# | Remove all the strings from the StringCollection
- C# | Remove the first occurrence from the StringCollection
- C# | Get an enumerator that iterates through StringCollection
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



