This implementation does not generally prohibit the use of types which are not
supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.
Properties
Capacity
public int Capacity { get; set; }
Gets and sets the capacity of the RepeatedField's internal array.
When set, the internal array is reallocated to the given capacity.
The new value is less than .
The zero-based index of the element to get or set.
Property Value
Type
Description
T
The element at the specified index.
Methods
Add(IEnumerable<T>)
public void Add(IEnumerable<T> values)
Adds all of the specified values into this collection. This method is present to
allow repeated fields to be constructed from queries within collection initializers.
Within non-collection-initializer code, consider using the equivalent AddRange(IEnumerable<T>)
method instead for clarity.
If the field type is
a message type, each element is also cloned; otherwise, it is
assumed that the field type is primitive (including string and
bytes, both of which are immutable) and so a simple copy is
equivalent to a deep clone.
Contains(T)
public bool Contains(T item)
Determines whether this collection contains the given item.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eRepeatedField<T>\u003c/code\u003e class in Google.Protobuf.Collections represents a collection with extra constraints, such as no null values, and additional features like deep cloning.\u003c/p\u003e\n"],["\u003cp\u003eIt implements various interfaces, including \u003ccode\u003eIList<T>\u003c/code\u003e, \u003ccode\u003eICollection<T>\u003c/code\u003e, \u003ccode\u003eIReadOnlyList<T>\u003c/code\u003e, and \u003ccode\u003eIEnumerable<T>\u003c/code\u003e, providing comprehensive collection functionalities.\u003c/p\u003e\n"],["\u003cp\u003eIt allows manipulation of its contents, supporting operations like adding, inserting, removing, clearing, and cloning elements.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRepeatedField<T>\u003c/code\u003e class includes properties like \u003ccode\u003eCapacity\u003c/code\u003e, \u003ccode\u003eCount\u003c/code\u003e, and \u003ccode\u003eIsReadOnly\u003c/code\u003e, giving control over its size, element count, and mutability.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to manage elements and data stream operations, such as \u003ccode\u003eAdd\u003c/code\u003e, \u003ccode\u003eAddRange\u003c/code\u003e, \u003ccode\u003eAddEntriesFrom\u003c/code\u003e, \u003ccode\u003eCalculateSize\u003c/code\u003e, \u003ccode\u003eWriteTo\u003c/code\u003e, and \u003ccode\u003eClone\u003c/code\u003e, which are core to its function.\u003c/p\u003e\n"]]],[],null,["# Class RepeatedField<T> (3.27.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.1 (latest)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections.RepeatedField-1)\n- [3.23.0](/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.Collections.RepeatedField-1)\n- [3.15.8](/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.Collections.RepeatedField-1) \n\n public sealed class RepeatedField\u003cT\u003e : IList\u003cT\u003e, ICollection\u003cT\u003e, IList, ICollection, IDeepCloneable\u003cRepeatedField\u003cT\u003e\u003e, IEquatable\u003cRepeatedField\u003cT\u003e\u003e, IReadOnlyList\u003cT\u003e, IReadOnlyCollection\u003cT\u003e, IEnumerable\u003cT\u003e, IEnumerable\n\nThe contents of a repeated field: essentially, a collection with some extra\nrestrictions (no null values) and capabilities (deep cloning). \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e RepeatedField\\\u003cT\\\u003e \n\nImplements\n----------\n\n[IList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1), [ICollection](https://learn.microsoft.com/dotnet/api/system.collections.generic.icollection-1), [IList](https://learn.microsoft.com/dotnet/api/system.collections.ilist), [ICollection](https://learn.microsoft.com/dotnet/api/system.collections.icollection), [IDeepCloneable](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1)[RepeatedField](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections.RepeatedField-1), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[RepeatedField](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections.RepeatedField-1), [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1), [IReadOnlyCollection](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlycollection-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable) \n\nInherited Members\n-----------------\n\n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals)\n\nNamespace\n---------\n\n[Google.Protobuf.Collections](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections)\n\nAssembly\n--------\n\nGoogle.Protobuf.dll\n\nRemarks\n-------\n\nThis implementation does not generally prohibit the use of types which are not\nsupported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.\n\nProperties\n----------\n\n### Capacity\n\n public int Capacity { get; set; }\n\nGets and sets the capacity of the RepeatedField's internal array.\nWhen set, the internal array is reallocated to the given capacity.\n[The new value is less than .](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)\n\n### Count\n\n public int Count { get; }\n\nGets the number of elements contained in the collection.\n\n### IsReadOnly\n\n public bool IsReadOnly { get; }\n\nGets a value indicating whether the collection is read-only.\n\n### this\\[int\\]\n\n public T this[int index] { get; set; }\n\nGets or sets the item at the specified index.\n\nMethods\n-------\n\n### Add(IEnumerable\\\u003cT\\\u003e)\n\n public void Add(IEnumerable\u003cT\u003e values)\n\nAdds all of the specified values into this collection. This method is present to\nallow repeated fields to be constructed from queries within collection initializers.\nWithin non-collection-initializer code, consider using the equivalent [AddRange(IEnumerable\\\u003cT\\\u003e)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections.RepeatedField-1#Google_Protobuf_Collections_RepeatedField_1_AddRange_System_Collections_Generic_IEnumerable__0__)\nmethod instead for clarity.\n\n### Add(T)\n\n public void Add(T item)\n\nAdds the specified item to the collection.\n\n### AddEntriesFrom(CodedInputStream, FieldCodec\\\u003cT\\\u003e)\n\n public void AddEntriesFrom(CodedInputStream input, FieldCodec\u003cT\u003e codec)\n\nAdds the entries from the given input stream, decoding them with the specified codec.\n\n### AddEntriesFrom(ref ParseContext, FieldCodec\\\u003cT\\\u003e)\n\n public void AddEntriesFrom(ref ParseContext ctx, FieldCodec\u003cT\u003e codec)\n\nAdds the entries from the given parse context, decoding them with the specified codec.\n\n### AddRange(IEnumerable\\\u003cT\\\u003e)\n\n public void AddRange(IEnumerable\u003cT\u003e values)\n\nAdds all of the specified values into this collection.\n\n### CalculateSize(FieldCodec\\\u003cT\\\u003e)\n\n public int CalculateSize(FieldCodec\u003cT\u003e codec)\n\nCalculates the size of this collection based on the given codec.\n\n### Clear()\n\n public void Clear()\n\nRemoves all items from the collection.\n\n### Clone()\n\n public RepeatedField\u003cT\u003e Clone()\n\nCreates a deep clone of this repeated field.\n\n**Remarks** \nIf the field type is\na message type, each element is also cloned; otherwise, it is\nassumed that the field type is primitive (including string and\nbytes, both of which are immutable) and so a simple copy is\nequivalent to a deep clone.\n\n### Contains(T)\n\n public bool Contains(T item)\n\nDetermines whether this collection contains the given item.\n\n### CopyTo(T\\[\\], int)\n\n public void CopyTo(T[] array, int arrayIndex)\n\nCopies this collection to the given array.\n\n### Equals(RepeatedField\\\u003cT\\\u003e)\n\n public bool Equals(RepeatedField\u003cT\u003e other)\n\nCompares this repeated field with another for equality.\n\n### Equals(object)\n\n public override bool Equals(object obj)\n\nDetermines whether the specified [object](https://learn.microsoft.com/dotnet/api/system.object), is equal to this instance.\n\n**Overrides** \n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object))\n\n### GetEnumerator()\n\n public IEnumerator\u003cT\u003e GetEnumerator()\n\nReturns an enumerator that iterates through the collection.\n\n### GetHashCode()\n\n public override int GetHashCode()\n\nReturns a hash code for this instance.\n\n**Overrides** \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode)\n\n### IndexOf(T)\n\n public int IndexOf(T item)\n\nReturns the index of the given item within the collection, or -1 if the item is not\npresent.\n\n### Insert(int, T)\n\n public void Insert(int index, T item)\n\nInserts the given item at the specified index.\n\n### Remove(T)\n\n public bool Remove(T item)\n\nRemoves the specified item from the collection\n\n### RemoveAt(int)\n\n public void RemoveAt(int index)\n\nRemoves the item at the given index.\n\n### ToString()\n\n public override string ToString()\n\nReturns a string representation of this repeated field, in the same\nway as it would be represented by the default JSON formatter.\n\n**Overrides** \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\n### WriteTo(CodedOutputStream, FieldCodec\\\u003cT\\\u003e)\n\n public void WriteTo(CodedOutputStream output, FieldCodec\u003cT\u003e codec)\n\nWrites the contents of this collection to the given [CodedOutputStream](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.CodedOutputStream),\nencoding each value using the specified codec.\n\n### WriteTo(ref WriteContext, FieldCodec\\\u003cT\\\u003e)\n\n public void WriteTo(ref WriteContext ctx, FieldCodec\u003cT\u003e codec)\n\nWrites the contents of this collection to the given write context,\nencoding each value using the specified codec."]]