mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
perf: Don't reinvent the wheel for TryElementAt extension method
This commit is contained in:
parent
f24f9458ca
commit
eb58e65574
1 changed files with 7 additions and 12 deletions
|
|
@ -163,21 +163,16 @@ namespace ICD.Common.Utils.Extensions
|
|||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (index < 0)
|
||||
throw new ArgumentException("Index must be greater or equal to 0", "index");
|
||||
|
||||
item = default(T);
|
||||
int eachIndex = 0;
|
||||
|
||||
foreach (T each in extends)
|
||||
try
|
||||
{
|
||||
if (eachIndex == index)
|
||||
{
|
||||
item = each;
|
||||
item = extends.ElementAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
eachIndex++;
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue