Chapter 2 : Data Processing Flashcards
Describe TextBox control ( 5 )
- Rectangular area
- Can accept keyboard input from the user
- Locates in the common control group of the toolbox
- Default name is textBoxn( n = 1 , 2 , 3 … )
- Double click to add it to the form
What property does TextBox controls?
- Text property which stores user inputs
- Only accepts string values
textBox1.Text = “Hello”;
Clear TextBox control content
textBox1.Text=””
How to declare variable in C#?
- DataType VariableName;
String text
double currency_rate
- Variable is a storage location in memory
What are the bytes used in int, float and double?
- int - 4 bytes
- float - 4 bytes
- double - 8 bytes
What is char used for?
- Storing a single character
- String is a collection of character
What is most data type known as?
- Primitive data types
Ways to use variables ( 3 )
- Store value
product = “Mac Book” - Assign to another value
productLabel.Text = product - Display in a message box
MessageBox/.Show(product)
What does a local variable belongs to?
- Method which it was declared
- Only statements inside that method can access the variable
What is the lifetime of a variable?
- Time period during which the variable exists in memory while the program is executing
List out the rules of variables ( 4 )
- Can assign a value only if the value is compatible with the variable’s data type
- A variable holds one value at a time
- Variable must be assigned before it can be used, I can initialize the variable with a value when declare it
- Multiple variables with the same type may be declared with one statement
Can the value of int and double surrounded by quotes?
- no
What does the decimal data type indicates?
- 128 bit data type
What is the advantages of decimal compared to double
- Makes appropriate for financial and monetary calculation since it has more precision and smaller range
How to declare decimal data type?
- decimal payRate = 28.5m
- decimal price = 8.95M
- Need to add the letter M ( or m ) to a decimal value
How to type casting?
- Use a cast operator with parentheses with the type keyword
( type )
wholeNumber = ( int ) moneynumber
List out arithmetic calculation ( 5 )
- , Add 2 numbers
- , Subtracts one number from another
- , Multiplies one number by another
- / , Divides one number by another and gives the quotient
- % , Divides one number by another and gives the remainder
List out the result of mixed data type ( 3 )
- When an operation involves an int and a double, int is treated as double and the result is double
- When an operation involves an int and a decimal, it is treated as decimal and the result is decimal
- An operation involving a double and decimal isn’t allowed
What are the types of input collected from the keyboard?
- Combinations of characters
( String Literals )
How to let string literals input from keyboard to convert string into numeric data types?
- int.Parse
- double.Parse
- decimal.Parse
How to show numeric values in lablel?
- Using ToString method
List out format strings for the ToString method
1.”N” or “n”
- Number Format
- 12.3 ToString (“n3”) = 12.300
2. “F” or “f”
- Fixed-point Scientific Format
- 123456.0 ToString(“f2”) = 123456.00
3. “E” or “e”
- Exponential Scientific Format
- 123456.0 ToString(“e3”) = 1.235e + 005
4. “C” or “c”
- Currency Format
- -1234567.8 ToString(“C”) = ( $1,234,567.80 )
5. “P” or “p”
- Percentage Format
- .234 ToString(“P”) = 23.40%
What is an exception?
- An exception is an unexpected error that happens while a program is running
What will happen if an exception isn’t handled by the program?
- The program will abruptly halt
List out the codes for exception handling
try{
}
catch {
}
- The catch block will execute when there is exception in the try block