perf: Don't reinvent the wheel for TryElementAt extension method

This commit is contained in:
Chris Cameron
2018-06-05 13:40:26 -04:00
parent f24f9458ca
commit eb58e65574

View File

@@ -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;
return true;
}
eachIndex++;
item = extends.ElementAt(index);
return true;
}
catch (Exception)
{
return false;
}
return false;