Logical Operators in C#: 'and', 'or' and 'not' : Logical Opertors « Language Basics « ASP.Net






Logical Operators in C#: 'and', 'or' and 'not'

<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void page_Load()
    {
         if(Page.IsPostBack)
         {
             int number1, number2, number3;
             number1 = Convert.ToInt32(txtNumber1.Text);
             number2 = Convert.ToInt32(txtNumber2.Text);
             number3 = Convert.ToInt32(txtNumber3.Text);
    
             lblExpression.Text = "number1 == 1 || !(number1==2) && !(number2==3)";
    
             if (number1 == 1 || !(number1==2) && !(number2==3))
                 lblResult.Text = "true";
             else
                 lblResult.Text = "false";
         }
    }
</script>
<html>
    <head>
    </head>
    <body>
        <form runat="server">
        Note: only works with integers<br>
        Number1 = <asp:TextBox runat="server" ID="txtNumber1" Text=5 width=30 />
        Number1 = <asp:TextBox runat="server" ID="txtNumber2" Text=2 width=30 />
        Number1 = <asp:TextBox runat="server" ID="txtNumber3" Text=3 width=30 /><br/>
    
        Press to see result<asp:Button runat="server" Text="Submit"/><br/>
        
        Logical expression is:<asp:Label runat="server" ID="lblExpression"/><br/>
        Logical expression result is:<asp:Label runat="server" ID="lblResult"/><br/>
        </form>
    </body>
</html>

           
       








Related examples in the same category

1.Logical AND Example (C#)