I have a property on a class that is an ISet. I\'m trying to get the results of a linq query into that property, but can\'t figure out how to do so.
Basically, look
If you need just readonly access to the set and the source is a parameter to your method, then I would go with
public static ISet EnsureSet(this IEnumerable source)
{
ISet result = source as ISet;
if (result != null)
return result;
return new HashSet(source);
}
The reason is, that the users may call your method with the ISet already so you do not need to create the copy.