Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:46:10+00:00 2026-05-31T04:46:10+00:00

I receive a string as a json parameter and it’s supposed to be a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:46:12+00:00Added an answer on May 31, 2026 at 4:46 am

    If you’re going to do this in various situations you should probably use:

    private static readonly HashSet<string> AllTimeZoneIds = 
        new HashSet<string>(TimeZoneInfo.GetSystemTimeZones()
                                        .Select(tz => tz.Id));
    

    Then you can just use:

    if (AllTimeZoneIds.Contains(timeZoneId))
    

    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:

    if (AllTimeZoneIds.Select(tz => tz.Id).Contains(timeZoneid))
    

    or

    if (AllTimeZoneIds.Any(tz => tz.Id == timeZoneid))
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that will receive a string , but before I can
How can I decode this JSON String which has been received as a parameter
I;m trying to parse a json string which I receive from web server as
I'm escaping all the string parameters I receive from a php form like this:
I need to convert a string to a JSON object that gets returned from
I receive a JSON response in an Ajax request from the server. This way
I'm trying to access a server so I can receive a JSON String. But
I use ASIHTTPRequest to get a token, and I receive this string: {Token:[{new:jkajshdkjashdjhasjkdhjkhd+sd==sfbjhdskfbks+sdjfbs==}]} I
Suppose I have a PHP script that returns a json response. It looks something
I'm using ajax to make a request on a servletand receive json String servlet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.