do
                {
                  Console.Write("     <jaar 1582 - 2500>...");
                } while(!int.TryParse(Console.ReadLine(), out jaar) && jaar < 1582);

Why doesn't this work in C#?
you can't test a integeren in a do while when there's a tryparse apperently
whats the best way of doing this?

Thank you for your time.

Recommended Answers

Why doesn't this work in C#?

Because you should be using || in your loop rather than &&. With &&, jaar will only be compared to 1582 if TryParse fails, which is somewhat nonsensical.

Jump to Post

All 2 Replies

Why doesn't this work in C#?

Because you should be using || in your loop rather than &&. With &&, jaar will only be compared to 1582 if TryParse fails, which is somewhat nonsensical.

Thank you for clearing this up.
And I now see the flaws in my logic. I should've known this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.