Table of Contents

Class BsonArray

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

Represents a BSON array.

[Serializable]
public class BsonArray : BsonValue, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonArray>, IEquatable<BsonArray>, IList<BsonValue>, ICollection<BsonValue>, IEnumerable<BsonValue>, IEnumerable
Inheritance
BsonArray
Implements
Derived
Inherited Members
Extension Methods

Constructors

BsonArray()

Initializes a new instance of the BsonArray class.

public BsonArray()

BsonArray(IEnumerable<BsonValue>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<BsonValue> values)

Parameters

values IEnumerable<BsonValue>

A list of values to add to the array.

BsonArray(IEnumerable<ObjectId>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<ObjectId> values)

Parameters

values IEnumerable<ObjectId>

A list of values to add to the array.

BsonArray(IEnumerable<bool>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<bool> values)

Parameters

values IEnumerable<bool>

A list of values to add to the array.

BsonArray(IEnumerable<DateTime>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<DateTime> values)

Parameters

values IEnumerable<DateTime>

A list of values to add to the array.

BsonArray(IEnumerable<double>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<double> values)

Parameters

values IEnumerable<double>

A list of values to add to the array.

BsonArray(IEnumerable<int>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<int> values)

Parameters

values IEnumerable<int>

A list of values to add to the array.

BsonArray(IEnumerable<long>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<long> values)

Parameters

values IEnumerable<long>

A list of values to add to the array.

BsonArray(IEnumerable<string>)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable<string> values)

Parameters

values IEnumerable<string>

A list of values to add to the array.

BsonArray(IEnumerable)

Initializes a new instance of the BsonArray class.

public BsonArray(IEnumerable values)

Parameters

values IEnumerable

A list of values to add to the array.

BsonArray(int)

Initializes a new instance of the BsonArray class.

public BsonArray(int capacity)

Parameters

capacity int

The initial capacity of the array.

Properties

BsonType

Gets the BsonType of this BsonValue.

public override BsonType BsonType { get; }

Property Value

BsonType

Capacity

Gets or sets the total number of elements the internal data structure can hold without resizing.

public virtual int Capacity { get; set; }

Property Value

int

Count

Gets the count of array elements.

public virtual int Count { get; }

Property Value

int

IsReadOnly

Gets whether the array is read-only.

public virtual bool IsReadOnly { get; }

Property Value

bool

this[int]

Gets or sets a value by position.

public override BsonValue this[int index] { get; set; }

Parameters

index int

The position.

Property Value

BsonValue

The value.

RawValues

Gets the array elements as raw values (see BsonValue.RawValue).

[Obsolete("Use ToArray to ToList instead.")]
public virtual IEnumerable<object> RawValues { get; }

Property Value

IEnumerable<object>

Values

Gets the array elements.

public virtual IEnumerable<BsonValue> Values { get; }

Property Value

IEnumerable<BsonValue>

Methods

Add(BsonValue)

Adds an element to the array.

public virtual BsonArray Add(BsonValue value)

Parameters

value BsonValue

The value to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<BsonValue>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<BsonValue> values)

Parameters

values IEnumerable<BsonValue>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<ObjectId>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<ObjectId> values)

Parameters

values IEnumerable<ObjectId>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<bool>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<bool> values)

Parameters

values IEnumerable<bool>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<DateTime>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<DateTime> values)

Parameters

values IEnumerable<DateTime>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<double>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<double> values)

Parameters

values IEnumerable<double>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<int>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<int> values)

Parameters

values IEnumerable<int>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<long>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<long> values)

Parameters

values IEnumerable<long>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable<string>)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable<string> values)

Parameters

values IEnumerable<string>

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

AddRange(IEnumerable)

Adds multiple elements to the array.

public virtual BsonArray AddRange(IEnumerable values)

Parameters

values IEnumerable

A list of values to add to the array.

Returns

BsonArray

The array (so method calls can be chained).

Clear()

Clears the array.

public virtual void Clear()

Clone()

Creates a shallow clone of the array (see also DeepClone).

public override BsonValue Clone()

Returns

BsonValue

A shallow clone of the array.

CompareTo(BsonArray)

Compares the array to another array.

public virtual int CompareTo(BsonArray rhs)

Parameters

rhs BsonArray

The other array.

Returns

int

A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other.

CompareTo(BsonValue)

Compares the array to another BsonValue.

public override int CompareTo(BsonValue other)

Parameters

other BsonValue

The other BsonValue.

Returns

int

A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other BsonValue.

Contains(BsonValue)

Tests whether the array contains a value.

public virtual bool Contains(BsonValue value)

Parameters

value BsonValue

The value to test for.

Returns

bool

True if the array contains the value.

CopyTo(BsonValue[], int)

Copies elements from this array to another array.

public virtual void CopyTo(BsonValue[] array, int arrayIndex)

Parameters

array BsonValue[]

The other array.

arrayIndex int

The zero based index of the other array at which to start copying.

CopyTo(object[], int)

Copies elements from this array to another array as raw values (see BsonValue.RawValue).

[Obsolete("Use ToArray or ToList instead.")]
public virtual void CopyTo(object[] array, int arrayIndex)

Parameters

array object[]

The other array.

arrayIndex int

The zero based index of the other array at which to start copying.

Create(object)

Creates a new BsonArray.

public static BsonArray Create(object value)

Parameters

value object

A value to be mapped to a BsonArray.

Returns

BsonArray

A BsonArray or null.

DeepClone()

Creates a deep clone of the array (see also Clone).

public override BsonValue DeepClone()

Returns

BsonValue

A deep clone of the array.

Equals(BsonArray)

Compares this array to another array.

public bool Equals(BsonArray obj)

Parameters

obj BsonArray

The other array.

Returns

bool

True if the two arrays are equal.

Equals(object)

Compares this BsonArray to another object.

public override bool Equals(object obj)

Parameters

obj object

The other object.

Returns

bool

True if the other object is a BsonArray and equal to this one.

GetEnumerator()

Gets an enumerator that can enumerate the elements of the array.

public virtual IEnumerator<BsonValue> GetEnumerator()

Returns

IEnumerator<BsonValue>

An enumerator.

GetHashCode()

Gets the hash code.

public override int GetHashCode()

Returns

int

The hash code.

IndexOf(BsonValue)

Gets the index of a value in the array.

public virtual int IndexOf(BsonValue value)

Parameters

value BsonValue

The value to search for.

Returns

int

The zero based index of the value (or -1 if not found).

IndexOf(BsonValue, int)

Gets the index of a value in the array.

public virtual int IndexOf(BsonValue value, int index)

Parameters

value BsonValue

The value to search for.

index int

The zero based index at which to start the search.

Returns

int

The zero based index of the value (or -1 if not found).

IndexOf(BsonValue, int, int)

Gets the index of a value in the array.

public virtual int IndexOf(BsonValue value, int index, int count)

Parameters

value BsonValue

The value to search for.

index int

The zero based index at which to start the search.

count int

The number of elements to search.

Returns

int

The zero based index of the value (or -1 if not found).

Insert(int, BsonValue)

Inserts a new value into the array.

public virtual void Insert(int index, BsonValue value)

Parameters

index int

The zero based index at which to insert the new value.

value BsonValue

The new value.

Remove(BsonValue)

Removes the first occurrence of a value from the array.

public virtual bool Remove(BsonValue value)

Parameters

value BsonValue

The value to remove.

Returns

bool

True if the value was removed.

RemoveAt(int)

Removes an element from the array.

public virtual void RemoveAt(int index)

Parameters

index int

The zero based index of the element to remove.

ToArray()

Converts the BsonArray to an array of BsonValues.

public virtual BsonValue[] ToArray()

Returns

BsonValue[]

An array of BsonValues.

ToList()

Converts the BsonArray to a list of BsonValues.

public virtual List<BsonValue> ToList()

Returns

List<BsonValue>

A list of BsonValues.

ToString()

Returns a string representation of the array.

public override string ToString()

Returns

string

A string representation of the array.

Operators

operator ==(BsonArray, BsonArray)

Compares two BsonArray values.

public static bool operator ==(BsonArray lhs, BsonArray rhs)

Parameters

lhs BsonArray

The first BsonArray.

rhs BsonArray

The other BsonArray.

Returns

bool

True if the two BsonArray values are equal according to ==.

operator !=(BsonArray, BsonArray)

Compares two BsonArray values.

public static bool operator !=(BsonArray lhs, BsonArray rhs)

Parameters

lhs BsonArray

The first BsonArray.

rhs BsonArray

The other BsonArray.

Returns

bool

True if the two BsonArray values are not equal according to ==.