1 / 14

Research Topics in Computational Science

Research Topics in Computational Science. Agenda. Commenting Our Code Variable Review Button Program – Add Textbox Getting text from textbox Converting text from textbox. Commenting. Makes code easier to read Helps you to remember Single & Multi-line comments // <- single line comment

raja-pena
Download Presentation

Research Topics in Computational Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  5. Declaring Variables • Many ways to do this: int age; // Most Common int age = 23; // Most Common <something> 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, 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;

More Related