コード例 #1
0
ファイル: NeedleBucket.cs プロジェクト: NN---/Theraot
 /// <summary>
 /// Sets the item at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="item">The item.</param>
 /// <param name="previous">The previous item in the specified index.</param>
 /// <returns>
 ///   <c>true</c> if the item was new; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception>
 public bool Exchange(int index, T item, out T previous)
 {
     if (_entries.Exchange(index, Reservoir.GetNeedle(item), out var found))
     {
         previous = default;
         return(true);
     }
     // TryGetValue is null resistant
     found.TryGetValue(out previous);
     // This is a needle that is no longer referenced, we donate it
     Reservoir.DonateNeedle(found);
     return(false);
 }
コード例 #2
0
ファイル: NeedleBucket.cs プロジェクト: pocketgems/Theraot
 /// <summary>
 /// Sets the item at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="item">The item.</param>
 /// <param name="previous">The previous item in the specified index.</param>
 /// <returns>
 ///   <c>true</c> if the item was new; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="System.ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception>
 public bool Exchange(int index, T item, out T previous)
 {
     TNeedle found;
     if (_entries.Exchange(index, NeedleReservoir<T, TNeedle>.GetNeedle(item), out found))
     {
         previous = default(T);
         return true;
     }
     // TryGetValue is null resistant
     found.TryGetValue(out previous);
     // This is a needle that is no longer referenced, we donate it
     NeedleReservoir<T, TNeedle>.DonateNeedle(found);
     return false;
 }