mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 05:05:05 +00:00
perf: Don't reinvent the wheel for TryElementAt extension method
This commit is contained in:
@@ -163,21 +163,16 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
if (extends == null)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
if (index < 0)
|
|
||||||
throw new ArgumentException("Index must be greater or equal to 0", "index");
|
|
||||||
|
|
||||||
item = default(T);
|
item = default(T);
|
||||||
int eachIndex = 0;
|
|
||||||
|
|
||||||
foreach (T each in extends)
|
try
|
||||||
{
|
{
|
||||||
if (eachIndex == index)
|
item = extends.ElementAt(index);
|
||||||
{
|
return true;
|
||||||
item = each;
|
}
|
||||||
return true;
|
catch (Exception)
|
||||||
}
|
{
|
||||||
|
return false;
|
||||||
eachIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user