Dela via


VBuffer<T>.GetItemOrDefault Method

Definition

Overloads

GetItemOrDefault(Int32)

A variant of GetItemOrDefault(Int32, T) that returns the value instead of passing it back using a reference parameter.

GetItemOrDefault(Int32, T)

Gets the item stored in this structure. In the case of a dense vector this is a simple lookup. In the case of a sparse vector, it will try to find the entry with that index, and set destination to that stored value, or if no such value was found, assign it the default value.

GetItemOrDefault(Int32)

A variant of GetItemOrDefault(Int32, T) that returns the value instead of passing it back using a reference parameter.

public T GetItemOrDefault (int index);
member this.GetItemOrDefault : int -> 'T
Public Function GetItemOrDefault (index As Integer) As T

Parameters

index
Int32

The index, which must be a non-negative number less than Length.

Returns

T

The value stored at that index, or if this is a sparse vector where this is an implicit entry, the default value for T.

Applies to

GetItemOrDefault(Int32, T)

Gets the item stored in this structure. In the case of a dense vector this is a simple lookup. In the case of a sparse vector, it will try to find the entry with that index, and set destination to that stored value, or if no such value was found, assign it the default value.

public void GetItemOrDefault (int index, ref T destination);
member this.GetItemOrDefault : int * 'T -> unit
Public Sub GetItemOrDefault (index As Integer, ByRef destination As T)

Parameters

index
Int32

The index, which must be a non-negative number less than Length.

destination
T

The value stored at that index, or if this is a sparse vector where this is an implicit entry, the default value for T.

Remarks

In the case where IsDense is true, this will take constant time since it an directly lookup. For sparse vectors, however, because it must perform a bisection search on the indices to find the appropriate value, that takes logarithmic time with respect to the number of explicitly represented items, which is to say, the Length of the return value of GetIndices().

For that reason, a single completely isolated lookup, since constructing ReadOnlySpan<T> as GetValues() does is not a free operation, it may be more efficient to use this method. However if one is doing a more involved computation involving many operations, it may be faster to utilize GetValues() and, if appropriate, GetIndices() directly.

Applies to