Skip to content

Commit d8c282e

Browse files
Revert "Adding TryDequeue method to Queue. resolves #4316"
This reverts commit d19afae.
1 parent 901cfdb commit d8c282e

File tree

1 file changed

+4
-27
lines changed
  • src/System.Collections/src/System/Collections/Generic

1 file changed

+4
-27
lines changed

src/System.Collections/src/System/Collections/Generic/Queue.cs

+4-27
Original file line numberDiff line numberDiff line change
@@ -240,40 +240,16 @@ IEnumerator IEnumerable.GetEnumerator()
240240
// InvalidOperationException.
241241
/// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.Dequeue"]/*' />
242242
public T Dequeue()
243-
{
244-
T removed;
245-
if (!TryDequeue(out removed))
246-
throw new InvalidOperationException(SR.InvalidOperation_EmptyQueue);
247-
248-
return removed;
249-
}
250-
251-
/// <summary>
252-
/// Attempts to remove and return the object at the beginning of the <see cref="Queue{T}"/>.
253-
/// </summary>
254-
/// <param name="item">
255-
/// When this method returns, if the operation was successful, <paramref name="item"/> contains the
256-
/// object removed. If no object was available to be removed, the value is unspecified.
257-
/// </param>
258-
/// <returns>
259-
/// true if an element was removed and returned from the beginning of the <see cref="Queue{T}"/>
260-
/// successfully; otherwise, false.
261-
/// </returns>
262-
/// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.TryDequeue"]/*' />
263-
public bool TryDequeue(out T item)
264243
{
265244
if (_size == 0)
266-
{
267-
item = default(T);
268-
return false;
269-
}
245+
throw new InvalidOperationException(SR.InvalidOperation_EmptyQueue);
270246

271-
item = _array[_head];
247+
T removed = _array[_head];
272248
_array[_head] = default(T);
273249
MoveNext(ref _head);
274250
_size--;
275251
_version++;
276-
return true;
252+
return removed;
277253
}
278254

279255
// Returns the object at the head of the queue. The object remains in the
@@ -443,6 +419,7 @@ public bool MoveNext()
443419

444420
arrayIndex -= capacity; // wrap around if needed
445421
}
422+
446423
_currentElement = array[arrayIndex];
447424
return true;
448425
}

0 commit comments

Comments
 (0)