Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a readonly ISet-like interface?

Tags:

c#

I am wondering if there is any set-like readonly interface that declares a Contains method in C#. I don't want to just implement the ISet interface because it has too many unnecessary methods.

My idea implementation would be like thi:

public class PositiveInt : IReadOnlySet<Int32> {    public bool Contains(Int32 n){       return n > 0;    } }  public class CraEmployeeNames:IReadOnlySet<String> {    public bool Contains(String n){       return !String.IsNullOrWhiteSpace(n) && n.StartsWith("Cra");    } }  

I can define my own IReadOnlySet, but want to ensure there is no built-in one before I do.

like image 975
Wei Ma Avatar asked May 14 '14 15:05

Wei Ma


1 Answers

How about the IImmutableSet<T> interface?

like image 145
xtofs Avatar answered Oct 11 '22 13:10

xtofs