mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Added extension method for peeking queues
This commit is contained in:
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Added extension method for peeking queues
|
||||
|
||||
## [9.3.0] - 2019-04-16
|
||||
### Added
|
||||
- Added SPlusUtils with ConvertToInt method taking LowWord/HighWord ushorts
|
||||
|
||||
@@ -43,5 +43,26 @@ namespace ICD.Common.Utils.Extensions
|
||||
item = extends.Dequeue();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Peeks the next item in the queue. Returns false if the queue is empty.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Peek<T>(this Queue<T> extends, out T item)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
item = default(T);
|
||||
|
||||
if (extends.Count == 0)
|
||||
return false;
|
||||
|
||||
item = extends.Peek();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user