mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Adding ElementAtOrDefault extension method that takes a default value
This commit is contained in:
parent
eb58e65574
commit
6fa3cc03ad
1 changed files with 16 additions and 1 deletions
|
|
@ -174,8 +174,23 @@ namespace ICD.Common.Utils.Extensions
|
|||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
/// <summary>
|
||||
/// Gets the element at the given index. Returns the specified default value if the index does not exist.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static T ElementAtOrDefault<T>(this IEnumerable<T> extends, int index, T defaultValue)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
T output;
|
||||
return extends.TryElementAt(index, out output) ? output : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue