title: Concurrent HashSet<T> in .NET Framework?
body: <p>I have the following class.</p>
  
  <pre><code>class Test{
      public HashSet&lt;string&gt; Data = new HashSet&lt;string&gt;();
  }
  </code></pre>
  
  <p>I need to change the field "Data" from different threads, so I would like some opinions on my current thread-safe implementation.</p>
  
  <pre><code>class Test{
      public HashSet&lt;string&gt; Data = new HashSet&lt;string&gt;();
  
      public void Add(string Val){
              lock(Data) Data.Add(Val);
      }
  
      public void Remove(string Val){
              lock(Data) Data.Remove(Val);
      }
  }
  </code></pre>
  
  <p>Is there a better solution, to go directly to field and protect it from concurrent access by multiple threads?</p>