© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
21 replies
Jexs(ping me)

Why does this work the way it does

I see this code:

Console.WriteLine("Type any number:  ");

int x;

if (int.TryParse(Console.ReadLine(), out x))
{
    //correct input
}
else
{
    //wrong input
}
Console.WriteLine("Type any number:  ");

int x;

if (int.TryParse(Console.ReadLine(), out x))
{
    //correct input
}
else
{
    //wrong input
}

and so far to my knowledge I know that for an if statement right after the if is the condition witch is true or false and if it’s true the first block executes if it’s false then the second block executes but in my mind I see that int.tryparse(console.readline(), out x) doesn’t fit the description of either being true or false(I guess cause the whole thing doesn’t look like a false or true statement/condition but the if still takes it) I don’t see how it’s supposed to evaluate to either true or false am I supposed to see it as if the value input is a string then
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Does this work the way I think it does?
C#CC# / help
2y ago
❔ ✅ Why does this not work???
C#CC# / help
3y ago
why does this Not work?
C#CC# / help
3y ago
❔ Why does this not work?
C#CC# / help
3y ago