Search Results for

    Show / Hide Table of Contents
    note

    VeloxDB is still in beta and APIs are subject to change. We are in the process of completing the documentation, so some sections may be incomplete or empty at this time.

    Class DatabaseArray<T>

    Represents a strongly typed array of simple types.

    Inheritance
    object
    DatabaseArray
    DatabaseArray<T>
    Implements
    IList<T>
    ICollection<T>
    IEnumerable<T>
    IEnumerable
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: VeloxDB.ObjectInterface
    Assembly: vlxdb.dll
    Syntax
    public abstract class DatabaseArray<T> : DatabaseArray, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
    Type Parameters
    Name Description
    T

    The type of elements in the array.

    Remarks

    VeloxDB allows you to specify an array like collection. DatabaseArray<T> can only hold simple types, if you need an array of references to other DatabaseObjects, use ReferenceArray<T>.

    DatabaseArray<T> is backed by an array. Array's size is initially set to capacity. As long as the capacity is larger than the length of the array Add is constant time operation (O(1)). When there is no more space in the backing array new array is allocated. The new array is twice the size of the previous one. Contents of the old array are copied to the new array. This gives DatabaseArray<T> amortized constant time adds, constant time direct access and linear remove.

    Examples

    The following example demonstrates how to declare a DatabaseArray<T> property.

    [DatabaseClass]
    public abstract class WeatherStation : DatabaseObject
    {
        [DatabaseProperty]
        public abstract double Lat { get; set; }
    
        [DatabaseProperty]
        public abstract double Long { get; set; }
    
        [DatabaseProperty]
        public abstract DatabaseArray<double> Temperature { get; set; }
    
        [DatabaseProperty]
        public abstract DatabaseArray<DateTime> Dates { get; set; }
    }
    

    The following example demonstrates how to use a DatabaseArray<T>.

    [DbAPIOperation]
    public void CreateTestStation(ObjectModel om)
    {
        WeatherStation ws = om.CreateObject<WeatherStation>();
    
        // Create an empty array
        ws.Dates = DatabaseArray<DateTime>.Create(4);
    
        // Add new dates to the end
        ws.Dates.Add(new DateTime(2022, 7, 1));
        ws.Dates.Add(new DateTime(2022, 7, 2));
        ws.Dates.Add(new DateTime(2022, 7, 3));
        ws.Dates.Add(new DateTime(2022, 7, 4));
    
        // Create an array from an existing collection
        ws.Temperature = DatabaseArray<double>.Create(new double[] { 33, 39, 41, 34 });
    
        // Remove by value
        ws.Temperature.Remove(41);
    
        // Remove using index
        ws.Temperature.RemoveAt(2);
    
        // Clear
        ws.Temperature.Clear();
        ws.Dates.Clear();
    }
    

    Properties

    Count

    Gets the number of items contained in the DatabaseArray<T>.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    int

    IsReadOnly

    Gets if the DatabaseArray<T> is Readonly. Always returns false.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    bool

    this[int]

    Index accessor.

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

    Index of the item to get.

    Property Value
    Type Description
    T

    Requested item.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    If index is less than 0 or greater than Count

    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Methods

    Add(T)

    Add an item to the end of the DatabaseArray<T>.

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

    The item to be added to the end of the DatabaseArray<T>.

    Exceptions
    Type Condition
    InvalidOperationException

    If the added item would cause Count to exceed int.MaxValue
    or
    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    AddRange(IEnumerable<T>)

    Adds the elements of the specified collection to the end of the DatabaseArray<T>.

    Declaration
    public void AddRange(IEnumerable<T> collection)
    Parameters
    Type Name Description
    IEnumerable<T> collection

    Collection whose elements will be added.

    Exceptions
    Type Condition
    ArgumentNullException

    collection is null.

    InvalidOperationException

    If the adding collection items would cause Count to exceed int.MaxValue
    or
    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Clear()

    Clears the DatabaseArray<T>.

    Declaration
    public void Clear()
    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Contains(T)

    Determines if an item is in the DatabaseArray<T>.

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

    The item to locate in the DatabaseArray<T>.

    Returns
    Type Description
    bool

    true if item is present in the DatabaseArray<T>, false if not.

    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    CopyTo(T[], int)

    Copies all items from the DatabaseArray<T> to the given array, starting at the specified index of the target array.

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

    Destination array.

    int arrayIndex

    Zero based index in array at which copying begins.

    Exceptions
    Type Condition
    ArgumentNullException

    array is null.

    ArgumentException

    There is not enough space in array to accommodate all the items.

    ArgumentOutOfRangeException

    arrayIndex is less than 0.

    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Create()

    Creates a new empty instance of the DatabaseArray<T>.

    Declaration
    public static DatabaseArray<T> Create()
    Returns
    Type Description
    DatabaseArray<T>

    Created DatabaseArray<T>

    Create(IEnumerable<T>)

    Creates a new instance of the DatabaseArray<T> that contains elements copied from the supplied collection.

    Declaration
    public static DatabaseArray<T> Create(IEnumerable<T> collection)
    Parameters
    Type Name Description
    IEnumerable<T> collection

    The collection whose elements are to be copied.

    Returns
    Type Description
    DatabaseArray<T>

    Created DatabaseArray<T>

    Exceptions
    Type Condition
    ArgumentNullException

    collection is null.

    Create(int)

    Creates a new empty instance of the DatabaseArray<T>. With specified capacity.

    Declaration
    public static DatabaseArray<T> Create(int capacity)
    Parameters
    Type Name Description
    int capacity

    Initial capacity. The initial size of the backing array.

    Returns
    Type Description
    DatabaseArray<T>

    Created DatabaseArray<T>

    GetEnumerator()

    Returns an enumerator that iterates through DatabaseArray<T>.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    IEnumerator<T>

    An enumerator.

    Remarks

    If DatabaseArray<T> changes, enumerator is invalidated. Any attempts to use it after that will throw an InvalidOperationException.

    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    IndexOf(T)

    Finds an item in the DatabaseArray<T> and returns its position.

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

    Item to find in DatabaseArray<T>.

    Returns
    Type Description
    int

    If the element is found, it return the zero based index in DatabaseArray<T>, otherwise it returns -1.

    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Insert(int, T)

    Inserts an item into DatabaseArray<T> at the specified position.

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

    Zero based position at which to insert item.

    T item

    The item to insert.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    If index is less than 0 or greater than Count

    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Remove(T)

    Remove the first occurrence of the item from the DatabaseArray<T>.

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

    Item to be removed.

    Returns
    Type Description
    bool

    true if item was removed, otherwise false.

    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    RemoveAt(int)

    Remove an item at the given position.

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

    Zero based index of an item to remove.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    If index is less than 0 or greater than Count

    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Implements

    IList<T>
    ICollection<T>
    IEnumerable<T>
    IEnumerable

    See Also

    ReferenceArray<T>
    In this article
    © 2025 Copyright: VeloxDB