C# | Check if the StringCollection is readonly (original) (raw)
Last Updated : 01 Feb, 2019
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:
CSHARP `
// 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:
Similar Reads
- C# | Check if StringCollection is synchronized (thread safe) 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.IsSynchronized property is used to get a value indicating whether access to the St 1 min read
- C# | Check if the specified string is in the StringCollection 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.Contains(String) method is used to check whether the specified string is in the St 2 min read
- C# | Check if a SortedList is read-only SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsReadOnly property is used to get a value which indicates that a So 2 min read
- C# | Check if two StringCollection objects are equal Equals(Object) Method which is inherited from the Object class is used to check if a specified StringCollection object is equal to another StringCollection object or not. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is to be compared with the current object. Return 2 min read
- C# | Check if the BitArray is read-only The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.IsReadOnly property is used to get a value indicati 2 min read
- C# | Check if the ArrayList is read-only ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.IsReadOnly property is used to check whether the ArrayList is rea 2 min read
- C# | Insert at the specified index in StringCollection 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.Insert(Int32, String) method is used to insert a string into the StringCollection 2 min read
- How to create a StringCollection in C# StringCollection() constructor is used to initializing a new instance of the StringCollection class. 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 2 min read
- C# StringCollection Class In C#, the StringCollection class is part of the System.Collections.Specialized namespace. It provides a collection of strings that allows us to store and manage a list of strings easily. This class is a type-safe collection that automatically resizes as needed.StringCollection class accepts null as 5 min read
- C# | Remove the first occurrence from the StringCollection 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.Remove(String) method is used to remove the first occurrence of a specific string 3 min read