System.InvalidOperationException: Sequence contains no elements

foreach (var keyCode in unexpectedKeyCodesDetected)
{
  string unexpected = expectedCapturedKeyCodes.Where(key => key == keyCode).First();
}

空集合时,从First()处 Throw the exceptoins. 

修改:  First() => FirstOrDefault(),然后对返回String做null判断。

原文地址:https://www.cnblogs.com/fdyang/p/3591864.html