Table of Contents

Struct SingleElementCollection<T>

Namespace
Garyon.Objects.Enumerators
Assembly
Garyon.dll

Represents a IReadOnlyCollection<T> that contains a single element.

public readonly struct SingleElementCollection<T> : IReadOnlyCollection<T?>, IEnumerable<T?>, IEnumerable, IEquatable<SingleElementCollection<T?>>

Type Parameters

T

The type of the stored element.

Implements
Inherited Members
Extension Methods

Constructors

SingleElementCollection(SingleElementCollection<T?>)

Initializes a new instance of the SingleElementCollection<T> struct, out of another SingleElementCollection<T>.

public SingleElementCollection(SingleElementCollection<T?> other)

Parameters

other SingleElementCollection<T>

The other SingleElementCollection<T> out of which to initialize this new collection.

SingleElementCollection(T?)

Initializes a new instance of the SingleElementCollection<T> struct, out of the single element that will be contained in the collection.

public SingleElementCollection(T? singleElement)

Parameters

singleElement T

The single element that will be contained in the collection. It may be null.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

Methods

Equals(SingleElementCollection<T?>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(SingleElementCollection<T?> other)

Parameters

other SingleElementCollection<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T?> GetEnumerator()

Returns

IEnumerator<T>

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

GetHashCode()

Gets the hash code of the current collection, which is determined by its only contained element.

public override int GetHashCode()

Returns

int

The hash code of its only contained element, if not null, otherwise default.

WithElement(T?)

Constructs a new SingleElementCollection<T> that contains the provided element.

public SingleElementCollection<T?> WithElement(T? newElement)

Parameters

newElement T

The new element that will be contained.

Returns

SingleElementCollection<T>

A new SingleElementCollection<T> containing the provided element.

Operators

operator ==(SingleElementCollection<T?>, SingleElementCollection<T?>)

public static bool operator ==(SingleElementCollection<T?> left, SingleElementCollection<T?> right)

Parameters

left SingleElementCollection<T>
right SingleElementCollection<T>

Returns

bool

operator !=(SingleElementCollection<T?>, SingleElementCollection<T?>)

public static bool operator !=(SingleElementCollection<T?> left, SingleElementCollection<T?> right)

Parameters

left SingleElementCollection<T>
right SingleElementCollection<T>

Returns

bool