I have a method that looks like this:
public static string MyMethod(string myParameter)
{
var defaultProperty = new Validation() {IDNumber = "ID Number Not Found", Logon = "ID Number Not Found" };
try
{
return lstLogons.DefaultIfEmpty(defaultProperty).Single(x => x.IDNumber == myParameter).Logon;
}
catch (Exception exception)
{
throw new ArgumentException(exception.Message, myParameter);
}
}
When testing, I am giving myParameter
a value that I know doesn't exist, so I want to be able to give a default value for these types of situations. But, instead it just throws an exception:
Sequence contains no matching element
I know it doesn't contain the element I am searching for.. hence the need/want for a default value.
How can I make this work?