Java has Collections.singletonList(T) which returns a List<T> of exactly one element. Is there something similar in C# that returns an IList?
Java has Collections.singletonList(T) which returns a List<T> of exactly one element. Is there something
Share
To answer your question, no. Sadly there is nothing built in, although it would often be useful when working with IEnumerable. You’ll have to roll your own.
Update
Instead of using workarounds, here’s an example of an efficient and immutable SingletonList that implements
IList<T>:Usage
Code