Download presentation
Presentation is loading. Please wait.
Published byMilton Rose Modified over 9 years ago
1
Research Topics in Computational Science
2
Agenda Commenting Our Code Variable Review Button Program – Add Textbox Getting text from textbox Converting text from textbox
3
Commenting Makes code easier to read Helps you to remember Single & Multi-line comments – // <- single line comment – /* multiline comment */ Be sure to comment your code!
4
Most Common C# Variable Types VariableUsage stringUse these for text intUse for whole numbers …, -2, -1, 0, 1, 2, … floatUse for scientific calculations decimalUsed for finances and percentages doubleDefault floating point number boolUsed for logical operations
5
Declaring Variables Many ways to do this: int age; // Most Common int age = 23; // Most Common int age; public int age; // We will learn more about private int age; // these examples later
6
Variable Assignment x = 1+2+3; The right hand side will be computed, then that value is assigned to x
7
Good Variable Names CamelCase – Capitalize the first letter of each word Long names are good Debate: To capitalize the first letter? – ALWAYS when it is a class – not always for variables
8
Math Operations Core 4: +, -, *, / Special: % (remainder after division) – What is -1%7? More math operations found in System.Math
9
Logic We can use a logic variable Or Compare 2 variables Compare Logic: – A and B, A or B, A xor B, A equal B – A && B, A || B, A ^ B, A == B Compare Numbers: – x y, x =y, x==y, x!=y Comparing Strings is Trickier
10
Let’s Make a Program Add a button – default name: button1 Add a textbox – default name: textBox1
11
Convert Class In our program we will use the class: Convert to convert from a string to a number. This can convert between many data types and is useful to know about. Usage (for Int32): x = Convert.ToInt32(inputString);
12
Try-Catch When don’t want our program to crash from a runtime error we can use Try-Catch Quickly create by typing try-”tab”-”tab” try { } catch (Exception ex) { mbox.Show(ex.Message()); }
13
If, Else if, Else double a, b, c; … if ( a>b) { // do something } else if ( a == b ) { // do something else } else { // if both above fail, do this }
14
Switch int age; … switch (age) { case 20: //do this if age == 20 break; case 25: // do this if age == 25 break; default: // do this if all the above cases fail break;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.