Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leave if statement

I have an if statement inside an if statement.

If the condition in the second if statement returns false, I want to go to the first else because there it sets my validation controls automatically.

I hope you understand

if (page.isvalid() )
{
    if (datetime.tryparse (date) == true)
    {
        // ok    
    } 
    else
    {
       //go to the other else
    }
}
else
{
    // want to go here
}

Edit:

Important is that I have to first validate the page because after the validation, I know I can parse the datetimes from the 2 input controls and check if the second one is greater than the first one. Otherwise it throws an exception, maybe, if the date is not valid.

like image 256
Marc Avatar asked Feb 26 '26 21:02

Marc


1 Answers

instead of DateTime.Parse(date) use

DateTime dt;
bool isParsed = DateTime.TryParse(date, out dt);

//if ( page.isvalid() && (datetime.parse (date) == true) )   
if ( page.isvalid() && isParsed )   
{        
     // ok        
}     
else    
{       
    // want to go here
}
like image 158
Saar Avatar answered Feb 28 '26 13:02

Saar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!