OneOrMany<T> Struct

Definition

A collection of T that is optimized for minimal space in the case of a single element.

generic <typename T>
 where T : classpublic value class OneOrMany
[System.Diagnostics.DebuggerDisplay("Count = {Count}")]
public struct OneOrMany<T> where T : class
[<System.Diagnostics.DebuggerDisplay("Count = {Count}")>]
type OneOrMany<'T (requires 'T : null)> = struct
Public Structure OneOrMany(Of T)

Type Parameters

T

Elemental type which must be a reference type. Note: null may not be used as a value in the collection.

Inheritance
OneOrMany<T>
Attributes

Remarks

While this type has a GetEnumerator() method, it does not implement IEnumerable<T>. This is to eliminate any unintentional boxing that will happen if a value type is passed to or returned from a method via its interface. The collection may still be enumerated in foreach statements (since the compiler uses pattern matching for that), but not elsewhere such as LINQ expressions.

Constructors

OneOrMany<T>(Int32)

Creates an instance of OneOrMany<T> that will use the given capacity to create its internal list.

OneOrMany<T>(List<T>)

Creates an instance of OneOrMany<T> using the given list as the content.

OneOrMany<T>(T)

Creates an instance of OneOrMany<T> using the given object as the content.

Properties

Count

Returns the count of the number of elements in the collection.

Item[Int32]

Gets the element at the specified index in the collection.

Methods

Add(T)

Add a new value to the collection.

AsList()

Returns the underlying list if this object contains > 1 item, otherwise null.

GetEnumerator()

Get an efficient enumerator for the collection

RemoveAt(Int32)

Remove the item at the specified index from the collection.

Applies to