Programming in Any Language
C# Decisions - Lessons
Decision Structure Introduction - The IF Statement - The IF/ELSE Statement - Nesting Decision Structures - IF/ELSE/IF - Logical Operators - Preventing Data Conversion Exceptions (TryParse) - Input Validation (Range Checking) - The SWITCH Statement - ListBox Intro - Radio Buttons - Check Box - Boolean Variables - String Comparisons
Decision Structure Introduction
Up to now we have been doing straight line programming. One line of code follows another. And then it’s done. That pretty much limits what we can do. So, it only makes sense that we expand on that. The tools in the decision structure allow our programs to branch off in other directions. And there is a lot of them. PDF: Slides
The IF Statement
Click to enlarge
In a decision program flows logically from the start and enters what we call a Boolean Expression. That expression is interrogated and if TRUE the program branches to a specific block of code (or single statement). If the expression is interrogated to be FALSE then that specific block of code is ignored and program flow continues normally.
Preventing Data Conversion Exceptions (TryParse)
Click to enlarge
Input Validation (Range Checking)
Click to enlarge
List Box Intro
The ListBox is basically an object that displays more than one item. It’s like a super label in a way. In other words, a collection of items can be displayed at once.
If the collection is too large to display in its entirety a scroll bar automatically appears allowing you navigate up and down through the list. PDF: Demo
Radio Buttons
Click for more info
Radio buttons allow users to select one choice from several possible choices. When a user clicks on a radio button the program automatically deselects any others. When you set up a program with radio buttons you typically place them inside a group box tool or a panel. PDF: Demo
Check Box
Click for more info
Check boxes allow users to select many choices from a group of possible choices. In fact the user can select them all! While they can be used independently, when you set up a program with check boxes you typically place them inside a group box tool or a panel just as you would the radio buttons. PDF: Demo
String Comparisons
Click to enlarge
For comparing strings we have the string.Compare method that is part of the C# language. Basically you compare two strings. One and two. If one is less than two the comparison evaluates to less than zero. If one is greater than two the comparison evaluates to greater than zero. If one is equal to zero the comparison evaluates to zero.