YamlArray Class
Definition
Represents a mutable YAML sequence node whose elements are YamlNode values.
public sealed class YamlArray : YamlNode, IList<YamlNode?>, ICollection<YamlNode?>, IEnumerable<YamlNode?>, IEnumerable
- Inheritance
-
YamlArray
- Implements
- Inherited Members
- Extension Methods
Remarks
A node may appear at most once in a tree. Adding, inserting, or assigning a node that already belongs to a container, this sequence included, throws an InvalidOperationException; removing or replacing an element, or clearing the sequence, detaches it so that it can be added elsewhere. Adding the sequence to itself or to one of its own descendants throws an InvalidOperationException as well. A null element is not a node and may appear any number of times.
Constructors
YamlArray()
public YamlArray()
Properties
Count
Gets the number of elements in the sequence.
public int Count { get; }
Property Value
- int
The element count.
IsReadOnly
Gets a value indicating whether the sequence is read-only.
public bool IsReadOnly { get; }
Property Value
this[int]
Gets or sets the element at the specified index.
public override YamlNode? this[int index] { get; set; }
Parameters
indexintThe zero-based index.
Property Value
Remarks
Assigning over an element detaches the replaced node, so that it can be added elsewhere. Assigning an element over itself leaves the sequence unchanged.
Exceptions
- ArgumentOutOfRangeException
indexis less than zero, or is greater than or equal to Count.- InvalidOperationException
The assigned node already belongs to a container, and is not the element at
index; or the assigned node is this sequence or one of its ancestors.
Methods
Add(YamlNode?)
Adds an element to the end of the sequence.
public void Add(YamlNode? item)
Parameters
itemYamlNodeThe element to add.
Exceptions
- InvalidOperationException
itemalready belongs to a container, or is this sequence or one of its ancestors.
Clear()
Removes all elements from the sequence, detaching each of them.
public void Clear()
Contains(YamlNode?)
Determines whether the sequence contains the specified element.
public bool Contains(YamlNode? item)
Parameters
itemYamlNodeThe element to locate.
Returns
CopyTo(YamlNode?[], int)
Copies the sequence elements to an array.
public void CopyTo(YamlNode?[] array, int arrayIndex)
Parameters
GetEnumerator()
Returns an enumerator over the elements.
public IEnumerator<YamlNode?> GetEnumerator()
Returns
- IEnumerator<YamlNode>
The element enumerator.
IndexOf(YamlNode?)
Returns the index of the specified element.
public int IndexOf(YamlNode? item)
Parameters
itemYamlNodeThe element to locate.
Returns
- int
The zero-based index, or
-1when not found.
Insert(int, YamlNode?)
Inserts an element at the specified index.
public void Insert(int index, YamlNode? item)
Parameters
Exceptions
- ArgumentOutOfRangeException
indexis less than zero, or is greater than Count.- InvalidOperationException
itemalready belongs to a container, or is this sequence or one of its ancestors.
Remove(YamlNode?)
Removes the first occurrence of the specified element, detaching it.
public bool Remove(YamlNode? item)
Parameters
itemYamlNodeThe element to remove.
Returns
RemoveAt(int)
Removes the element at the specified index, detaching it.
public void RemoveAt(int index)
Parameters
indexintThe zero-based index.
Exceptions
- ArgumentOutOfRangeException
indexis less than zero, or is greater than or equal to Count.
WriteTo(Utf8YamlWriter)
Writes this node to the given writer.
public override void WriteTo(Utf8YamlWriter writer)
Parameters
writerUtf8YamlWriterThe writer to emit into.
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
IEnumerator? IEnumerable.GetEnumerator()
Returns
- IEnumerator
An IEnumerator object that can be used to iterate through the collection.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |