Lets say I want to loop trough all the files in a directory and if the file has an extension of an image format such as jpeg, bmp, or png, I want to copy the file to another directory. Is there a way I can check for all image extensions without chaining || together? Here is an example:
Instead of:
if(file.Extension == ".jpg" ||
file.Extension == ".jpeg" ||
file.Extension == ".bmp" ||
file.Extension == ".png")
//Copy To Image directory
Can I do something like:
if (file.Extension.Contains(...)).
I know Contains exists, but it does not take an array of values (extensions in this case)
If you have a LOT of extensions I’d switch it from a List to a HashSet, but for a small number of values (i.e. 4) a List will be either the same or quicker.