Writing Nested If condition using C# in ASP.Net

Last Reply on Jul 21, 2016 09:52 AM By Shashikant

Posted on Jul 21, 2016 07:45 AM

hi

I use if condition in behind code:

if (Ch3D.Checked == true)
{
    _cmd.Parameters.AddWithValue("@GenrePre", "1");

}
else
{
    if (ChOscar.Checked == true)
    {
        _cmd.Parameters.AddWithValue("@GenrePre", "2");

    }
    else
    {

        if (ChDobleF.Checked == true)
        {
            _cmd.Parameters.AddWithValue("@GenrePre", "3");

        }
    }
}

as you see I used neasted if else condition is there other code that I use it instead of neasted if else contition?

best regards

neda

 

Posted on Jul 21, 2016 09:52 AM
nedash says:
if (Ch3D.Checked == true)
            {
                _cmd.Parameters.AddWithValue("@GenrePre", "1");
 
            }
            else
            {
                if (ChOscar.Checked == true)
                {
                    _cmd.Parameters.AddWithValue("@GenrePre", "2");
 
                }
                else {
 
                    if (ChDobleF.Checked == true)
                    {
                        _cmd.Parameters.AddWithValue("@GenrePre", "3");
 
                    }
                }
            }

Hi,

as per your condition your code is proper.