if (File.Exists(file.csv))
{
return file.csv;
}
else if (File.Exists(file.dbf))
{
return file.dbf;
}
Can I simplify this expression using one line?
If you're willing to accept an InvalidOperationException if no matching file exists:
return new[]{file.csv, file.dbf}.First(File.Exists);
Edit:
If you don't want an exception (you removed that part from your question), use FirstOrDefault() instead and check for null, as Willem Duncan mentioned already in his comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With