ASP.NET Code
  Home arrow ASP.NET Code arrow Page 6 - ASP.NET Basics (part 3): Hard Choices
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

ASP.NET Basics (part 3): Hard Choices
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2003-08-19

    Table of Contents:
  • ASP.NET Basics (part 3): Hard Choices
  • Apples And Oranges
  • Do It Or Else...
  • Cookie-Cutter Code
  • Three In One
  • Friday The 13th
  • Switching Things Around
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    ASP.NET Basics (part 3): Hard Choices - Friday The 13th
    (Page 6 of 8 )

    If you take a close look at the "if-else if-else" statement example a few pages back, you'll notice that the conditional expression


    temp 25 && temp >= 10

    is slightly different from the ones you've been used to thus far. This is because C# also allows you to combine multiple conditions into a single expression, with the help of an animal called a "logical operator".

    The following table should make this clearer.

    assume delta = 12, gamma = 12 and omega = 9

    Operator What It Means Expression Result
    --------------------------------------------------------------------------
    && AND delta == gamma && delta > omega True

    && AND delta == gamma && delta < omega False

    || OR delta == gamma || delta < omega True

    || OR delta > gamma || delta < omega False

    ! NOT !delta False

    Logical operators are useful because they allow you to logically combine or group different conditional tests together, thereby making it possible to enforce complex business rules in your application logic without too much effort.

    So, instead of something as ugly as this


    <%
    if (
    day == "Friday")
    {
    if (
    date == "13")
    {
    if (
    time == "1300 hours")
    {
    fortune "Brace yourself for some bad luck, it's Friday the 13th";
    }
    }
    }

    %>

    you could have something as elegant as this.


    <%

    if (
    day == "Friday" && date == "13" && time == "1300 hours")
    {
    fortune "Brace yourself for some bad luck, it's Friday the 13th"; }

    %>

    More ASP.NET Code Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway