Download presentation
Presentation is loading. Please wait.
Published byDeven Cleere Modified over 10 years ago
1
If Statements, Try Catch and Validation
2
The main statement used in C# for making decisions depending on different conditions is called the If statement. A second useful structure in a similar vein is called Try Catch.
3
The If Statement If (condition) { ‘execute the code here }
4
else
5
Conditions >a > bis a greater than b <a < bis a less than b >=a >= bis a greater than or equal to b <=a <= bis a less than or equal to b ==a == bis a the same as b !=a != bare a and b different
6
else if
7
Logical Operators Notice the “and” logical operator & in the Boolean expression. & is one of a range of logical operators that may also be used to evaluate data. “And” may be used should we want to test if a value was greater than one value “And” less than another value. Another useful operator is “Or” indicated by the symbol | In which case you might ask the question is a value one value “Or” another.
8
Try and Catch
9
Validation "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." Rich Cook
10
Validation Systems must be both Robust Responsive
11
What is Wrong with this? What about those bigger & better idiots?
12
Testing for a Valid Number
13
Testing for a Valid Date
14
Testing for a Blank Field
15
Testing for Text over a Certain Number of Characters
16
Validating an Email Address Question – What is the problem with the above code?
17
What about the following… fred@nothing
18
Better…
19
Better still …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.