I want to validate a file uploader, by file extension. If the file extension is not equal to .jpg, .jpeg, .gif, .png, .bmp then throw validation error.
Is there a way to do this without looping through each type?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just build a collection – if it’s small, just about any collection will do:
That does loop over all the values of course – but for small collections, that shouldn’t be too expensive. For a large collection of strings you’d want to use something like
HashSet<string>instead, which would provide a more efficient lookup.