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
TThe type of the stored element.
- Implements
-
IEnumerable<T>
- 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
otherSingleElementCollection<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
singleElementTThe 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
otherSingleElementCollection<T>An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
WithElement(T?)
Constructs a new SingleElementCollection<T> that contains the provided element.
public SingleElementCollection<T?> WithElement(T? newElement)
Parameters
newElementTThe 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
leftSingleElementCollection<T>rightSingleElementCollection<T>
Returns
operator !=(SingleElementCollection<T?>, SingleElementCollection<T?>)
public static bool operator !=(SingleElementCollection<T?> left, SingleElementCollection<T?> right)
Parameters
leftSingleElementCollection<T>rightSingleElementCollection<T>