I don’t know if this question has been asked before. The way I know to do it am not convenient with it sometimes.
string[] exts = { "png", "jpg", "gif" };
if (exts.Contains(Path.GetExtension(filename)))
{
}
I would like to change the positions of the variables
if(Path.GetExtension(filename) is in exts)
{
}
Anyway to do it would be appreciated, LINQ, array function, etc
You can write an extension method on
stringthat takes astring[]and tests whether the string is in the array (usingContains) – then you would have"aString".IsIn(myArray).