simplified if else

c#

Solution

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.

Problem

``` 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?

Original source