title: C# Non-Generic ISet Interface
body: <p><code>.NET 4.0</code> introduced a non-generic <code>IList</code> which exposes the ability to add values to the List without needing to know the generic type. This is useful because it allows me to write a method such as the following:</p>
  
  <pre><code>void CreateListFromBytes(IntPtr bytes, Type outputType, out object outputObject)
  {
      Type elementType = outputType.GenericTypeArguments[0];
      int numberOfElements = ReadHeaderBytes(bytes);
      bytes += Marshal.SizeOf(typeof(int));
  
      IList outputList = (IList) Activator.CreateInstance(outputType);
      for (int i = 0; i &lt; numberOfElements; i++)
      {
          object element = ReadDataBytes(bytes, elementType);
          bytes += Marshal.SizeOf(elementType);
          outputList.Add(element);
      }
  
      outputObject = outputList;
  }
  </code></pre>
  
  <p>However, when I try to implement a method with a similar style for <code>HashSet</code> or <code>ISet</code>, there is not such non-generic interface I can find that exposes and <code>Add()</code> method.</p>
  
  <p>I am wondering if such an interface exists that I may have missed. If not, I am wondering how I can go about adding elements to object I know for certain is <code>Set</code> (since I created it the <code>Activator.CreateInstance()</code>)</p>