Should I check Count
before Linq Single() call if I expect only one element?
if (objects.Count != 1)
{
throw new
InvalidOperationException(
"%Collection% should contain one %element%, but now it's: "
+ objects.Count);
}
return objects.Single();
Single
implements the same check and throwing. But its message is less specific.
P.S. in my case wrong count is handled just writing log message like
_log.Error("Error during %operation%", ex);
task.Complete(TaskResult.Fail);
Single
methods outputs doesn't help at all. \$\endgroup\$ – t3chb0t Jun 16 '16 at 6:53