Do you have an idea to avoid doing multiple String.Equals? For instance:
if (interSubDir.Equals("de") || interSubDir.Equals("de-DE"))
Thanks!
If you are simply trying to make it more readable, or require less typing, you can write a string extension method like so:
public static class StringExt
{
public static bool EqualsAnyOf(this string value, params string[] targets)
{
return targets.Any(target => target.Equals(value));
}
}
Which you can use as follows:
if (interSubDir.EqualsAnyOf("de", "de-DE"))
Or
if (interSubDir.EqualsAnyOf("de", "de-DE", "en", "en-GB", "en-US"))
and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With