Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I used to search the file names using below
C#
Directory.GetFiles(@"C:/", "*.aspx", SearchOption.AllDirectories).First(f => System.IO.Path.GetFileName(f).Contains("data"))

when a file name with "data" doesn't contains it showing the error as "Sequence contains no matching element" i want to skip to else conditions without showing this error how can i solve...
pleas help me
Posted
Updated 22-Jun-14 21:57pm
v2

1 solution

You should use FirstOrDefault() in place of First(), then to test the result for null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900