Show / Hide Table of Contents

Class RepeatedField<T>

The contents of a repeated field: essentially, a collection with some extra restrictions (no null values) and capabilities (deep cloning).

Inheritance
System.Object
RepeatedField<T>
Implements
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.IList
System.Collections.ICollection
IDeepCloneable<RepeatedField<T>>
System.IEquatable<RepeatedField<T>>
System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Protobuf.Collections
Assembly: Google.Protobuf.dll
Syntax
public sealed class RepeatedField<T> : IList<T>, ICollection<T>, IList, ICollection, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name Description
T

The element type of the repeated field.

Remarks

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

Count

Gets the number of elements contained in the collection.

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32
Implements
System.Collections.Generic.ICollection<T>.Count
System.Collections.ICollection.Count
System.Collections.Generic.IReadOnlyCollection<T>.Count

IsReadOnly

Gets a value indicating whether the collection is read-only.

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
System.Boolean
Implements
System.Collections.Generic.ICollection<T>.IsReadOnly
System.Collections.IList.IsReadOnly

Item[Int32]

Gets or sets the item at the specified index.

Declaration
public T this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index

The zero-based index of the element to get or set.

Property Value
Type Description
T

The element at the specified index.

Implements
System.Collections.Generic.IList<T>.Item[System.Int32]
System.Collections.Generic.IReadOnlyList<T>.Item[System.Int32]

Methods

Add(T)

Adds the specified item to the collection.

Declaration
public void Add(T item)
Parameters
Type Name Description
T item

The item to add.

Implements
System.Collections.Generic.ICollection<T>.Add(T)

Add(IEnumerable<T>)

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.

Declaration
public void Add(IEnumerable<T> values)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> values

The values to add to this collection.

AddEntriesFrom(CodedInputStream, FieldCodec<T>)

Adds the entries from the given input stream, decoding them with the specified codec.

Declaration
public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
Parameters
Type Name Description
CodedInputStream input

The input stream to read from.

FieldCodec<T> codec

The codec to use in order to read each entry.

AddRange(IEnumerable<T>)

Adds all of the specified values into this collection.

Declaration
public void AddRange(IEnumerable<T> values)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> values

The values to add to this collection.

CalculateSize(FieldCodec<T>)

Calculates the size of this collection based on the given codec.

Declaration
public int CalculateSize(FieldCodec<T> codec)
Parameters
Type Name Description
FieldCodec<T> codec

The codec to use when encoding each field.

Returns
Type Description
System.Int32

The number of bytes that would be written to a CodedOutputStream by WriteTo(CodedOutputStream, FieldCodec<T>), using the same codec.

Clear()

Removes all items from the collection.

Declaration
public void Clear()
Implements
System.Collections.Generic.ICollection<T>.Clear()
System.Collections.IList.Clear()

Clone()

Creates a deep clone of this repeated field.

Declaration
public RepeatedField<T> Clone()
Returns
Type Description
RepeatedField<T>

A deep clone of this repeated field.

Implements
IDeepCloneable<T>.Clone()
Remarks

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)

Determines whether this collection contains the given item.

Declaration
public bool Contains(T item)
Parameters
Type Name Description
T item

The item to find.

Returns
Type Description
System.Boolean

true if this collection contains the given item; false otherwise.

Implements
System.Collections.Generic.ICollection<T>.Contains(T)

CopyTo(T[], Int32)

Copies this collection to the given array.

Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type Name Description
T[] array

The array to copy to.

System.Int32 arrayIndex

The first index of the array to copy to.

Implements
System.Collections.Generic.ICollection<T>.CopyTo(T[], System.Int32)

Equals(RepeatedField<T>)

Compares this repeated field with another for equality.

Declaration
public bool Equals(RepeatedField<T> other)
Parameters
Type Name Description
RepeatedField<T> other

The repeated field to compare this with.

Returns
Type Description
System.Boolean

true if other refers to an equal repeated field; false otherwise.

Implements
System.IEquatable<T>.Equals(T)

Equals(Object)

Determines whether the specified System.Object, is equal to this instance.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The System.Object to compare with this instance.

Returns
Type Description
System.Boolean

true if the specified System.Object is equal to this instance; otherwise, false.

Overrides
System.Object.Equals(System.Object)

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<T>

An enumerator that can be used to iterate through the collection.

Implements
System.Collections.Generic.IEnumerable<T>.GetEnumerator()

GetHashCode()

Returns a hash code for this instance.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Overrides
System.Object.GetHashCode()

IndexOf(T)

Returns the index of the given item within the collection, or -1 if the item is not present.

Declaration
public int IndexOf(T item)
Parameters
Type Name Description
T item

The item to find in the collection.

Returns
Type Description
System.Int32

The zero-based index of the item, or -1 if it is not found.

Implements
System.Collections.Generic.IList<T>.IndexOf(T)

Insert(Int32, T)

Inserts the given item at the specified index.

Declaration
public void Insert(int index, T item)
Parameters
Type Name Description
System.Int32 index

The index at which to insert the item.

T item

The item to insert.

Implements
System.Collections.Generic.IList<T>.Insert(System.Int32, T)

Remove(T)

Removes the specified item from the collection

Declaration
public bool Remove(T item)
Parameters
Type Name Description
T item

The item to remove.

Returns
Type Description
System.Boolean

true if the item was found and removed; false otherwise.

Implements
System.Collections.Generic.ICollection<T>.Remove(T)

RemoveAt(Int32)

Removes the item at the given index.

Declaration
public void RemoveAt(int index)
Parameters
Type Name Description
System.Int32 index

The zero-based index of the item to remove.

Implements
System.Collections.Generic.IList<T>.RemoveAt(System.Int32)
System.Collections.IList.RemoveAt(System.Int32)

ToString()

Returns a string representation of this repeated field, in the same way as it would be represented by the default JSON formatter.

Declaration
public override string ToString()
Returns
Type Description
System.String
Overrides
System.Object.ToString()

WriteTo(CodedOutputStream, FieldCodec<T>)

Writes the contents of this collection to the given CodedOutputStream, encoding each value using the specified codec.

Declaration
public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
Parameters
Type Name Description
CodedOutputStream output

The output stream to write to.

FieldCodec<T> codec

The codec to use when encoding each value.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Declaration
void ICollection.CopyTo(Array array, int index)
Parameters
Type Name Description
System.Array array
System.Int32 index
Implements
System.Collections.ICollection.CopyTo(System.Array, System.Int32)

ICollection.IsSynchronized

Declaration
bool ICollection.IsSynchronized { get; }
Returns
Type Description
System.Boolean
Implements
System.Collections.ICollection.IsSynchronized

ICollection.SyncRoot

Declaration
object ICollection.SyncRoot { get; }
Returns
Type Description
System.Object
Implements
System.Collections.ICollection.SyncRoot

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

An System.Collections.IEnumerator object that can be used to iterate through the collection.

Implements
System.Collections.IEnumerable.GetEnumerator()

IList.Add(Object)

Declaration
int IList.Add(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Int32
Implements
System.Collections.IList.Add(System.Object)

IList.Contains(Object)

Declaration
bool IList.Contains(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Boolean
Implements
System.Collections.IList.Contains(System.Object)

IList.IndexOf(Object)

Declaration
int IList.IndexOf(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Int32
Implements
System.Collections.IList.IndexOf(System.Object)

IList.Insert(Int32, Object)

Declaration
void IList.Insert(int index, object value)
Parameters
Type Name Description
System.Int32 index
System.Object value
Implements
System.Collections.IList.Insert(System.Int32, System.Object)

IList.IsFixedSize

Declaration
bool IList.IsFixedSize { get; }
Returns
Type Description
System.Boolean
Implements
System.Collections.IList.IsFixedSize

IList.Item[Int32]

Declaration
object IList.this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index
Returns
Type Description
System.Object
Implements
System.Collections.IList.Item[System.Int32]

IList.Remove(Object)

Declaration
void IList.Remove(object value)
Parameters
Type Name Description
System.Object value
Implements
System.Collections.IList.Remove(System.Object)
Back to top