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) 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);
{
item = each;
return true; return true;
} }
catch (Exception)
eachIndex++; {
return false;
} }
return false; return false;