I receive a string as a json parameter and it’s supposed to be a timezone ID. I want to check for that.
This is what I have:
TheTimezoneID = TheTimezoneID.Trim();
var AllTimezones = TimeZoneInfo.GetSystemTimeZones();
if (TheTimezoneID "is a valid .net timezone" == true) {}
What’s the linq expression that’ll test if TheTimezoneID is in AllTimezones? I tried using .Any but it’s not working.
Thanks.
If you’re going to do this in various situations you should probably use:
Then you can just use:
There’s no need to use LINQ to iterate over the whole time zone list on each time when a hash set can just perform an O(1) lookup.
If you’re just curious about using
Any, it would be:or
Note that “time zone ID” is a pretty woolly concept. This will check if it’s a valid .NET time zone ID. If you’re actually getting time zones like “Europe/London”, that’s a different matter.