Presentation is loading. Please wait.

Presentation is loading. Please wait.

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.

Similar presentations


Presentation on theme: "If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement."— Presentation transcript:

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 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 Address Question – What is the problem with the above code?

17 What about the following…

18 Better…

19 Better still …


Download ppt "If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement."

Similar presentations


Ads by Google