Esempio n. 1
0
 /// <summary>Retrieves a reference to the specified item.</summary>
 /// <typeparam name="T">The type of the items in the set.</typeparam>
 /// <param name="tset">The set to search.</param>
 /// <param name="item">The item sought.</param>
 /// <returns>A reference to a matching item if it is present in the set, null otherwise.</returns>
 /// <remarks>This allows use of the set to restrain a group of objects to exclude duplicates, allowing for
 /// reduced memory use, and reference-based equality checking, comparable with how
 /// <see cref="string.IsInterned(string)"/> allows one to check for a copy of a string in the CLR intern pool,
 /// but also allowing for removal, clearing and multiple pools. This is clearly only valid for reference types.
 /// </remarks>
 public static T Find <T>(this ThreadSafeSet <T> tset, T item) where T : class
 {
     ThreadSafeSet <T> .Box box = tset.Obtain(item);
     return(box == null ? null : box.Value);
 }