Code Review Flashcards

1
Q

What property is being used to change the background color for every element?

A
  1. BackColor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What property is being used to set the element’s variable name?

A
  1. Name ( in Design )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List out 5 values for image size mode

A
  1. Zoom
  2. StretchImage
  3. Normal
  4. AutoSize
  5. CenterImage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List out 2 values for the Visible property

A
  1. True
  2. False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to change the element text shown at the UI?

A
  1. Change the text at the Text property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List out 9 properties for Text Alignment

A
  1. Top Left
  2. Top Center
  3. Top Right
  4. Middle Left
  5. Middle Center
  6. Middle Right
  7. Bottom Left
  8. Bottom Center
  9. Bottom Right
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What property is set to ensure that the elements doesn’t relocate when the windows expand or shrink?

A
  1. Anchor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What property is being used to change the text color?

A
  1. ForeColor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What property in TextBox is used to hide the letters input?

A
  1. PasswordChar
  • Example
    When set to *
    Input 1234 will turn **
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

List out 5 types of events

A
  1. Activate Events
    • Selects item on screen
  2. Changed Events
    • Modified control property
  3. Focus Events
    • Control gets or loses focus
  4. Key Events
    • Interact with keyboard
  5. Mouse Events
    • Interact with mouse
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to show the dialog box the shows the message when a button is pressed?

A

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(“Hello”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What property allows changing the element’s text font, font style, and font size?

A
  1. Font
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

List out 3 values that can be set in the BorderStyle

A
  1. None
  2. FixedSingle
  3. Fixed3D
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which properties can be used to enable auto size method?

A
  1. AutoSize
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an assignment operator?

A
  1. =
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to assign the text from label1 to another text Hello?

A
  1. label1.Text = “Hello”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to change the label1 background color to another color ( blue ) after a button is pressed?

A

private void button1_Click(object sender, EventArgs e)
{
label1.BackColor = Color.Blue ;
}

this.BackColor = Color.Red;
// Will change the background color for the current form

this inside a class means the current instance of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to use concatenation?

A
  1. Use the + operator on string value to combine 2 string

“Welcome” + “to C#”

1 + 1 = 2
“1” + “1” = 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

List out how to write comment on
1. Single Line Comment
2. Multiline Comment

A
  1. //
  2. /**/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is identation being used for?

A
  1. Make code more human readable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to close the current application form when a button is clicked?

A

private void exitButton_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

List out 3 types of error

A
  1. Syntax Errors
    • Show with jagged line
    • MessageBox.Sh(“Hi)
  2. Run-time Errors
    • Errors when program runs
    • num = 100 / 0
  3. Logic ( Semantic ) Errors
    • age = 2024 + bornYear
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to declare variable car to store string Perodua?

A
  1. string car = “Perodua”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to declare variable age with current year ( DateTime ) minus birth year ( txtBornYear ) ?

A

int birthYear = int.Parse(txtBornYear.Text);
static int currentYear = DateTime.Now.Year;

int age = currentYear - birthYear ;

Improvement with Error Checking
int birthYear;
if (int.TryParse(txtBornYear.Text, out birthYear))
{
int currentYear = DateTime.Now.Year;
int age = currentYear - birthYear;
MessageBox.Show(“You are “ + age + “ years old.”);
}
else
{
MessageBox.Show(“Please enter a valid year.”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
List out 3 naming conventions for Variable Names
1. The first character must be a letter ( upper / lowercase ) or an underscore ( _ ) 2. Name cannot contain spaces 3. Don't use C# Keywords or Reserved Words
26
How to assign string variable productDesciption value to label productLabel ?
productLabel.Text = productDescription MessageBox.Show(productLabel)
27
Create a variable message then combine "Hello" and "World" and show it in Message Box
string message message = "Hello" + "World" MessageBox.Show(message)
28
Can I access string myName at the method secondButton_Click? ``` private void firstButton_Click(object sender, EventArgs e) { // Local variable string myName; myName = nameTextBox.Text; } private void secondButton_Click(object sender, EventArgs e) { outputLabel.Text = myName; } ```
1. No, because string myName is a **local variable** inside firstButton_Click
29
How to declare firstName, middleName and lastName as a string variable in one line?
string firstName, middleName, lastName; firstName = "Leon"; middleName = "Scott"; lastName = "Kennedy"; MessageBox.Show($"The character you played as in RE4 is : {firstName} {middleName} {lastName}");
30
What is the most important symbol in the exam?
1. The semicolon ( ; ) when the C# code ends string firstName = "Leon"**;**
31
Which value cannot surround by double quote ( string ) ? ( 9 )
1. int 2. double 3. float 4. boolean 5. char 6. array 7. list 8. null 9. decimal
32
What is the final value when an operation involves an int and a double?
1. int is treated as double and the result is double
33
Is an operation involving a double and decimal is allowed?
1. No
34
How to perform 5 + 4 and pass it to message box ?
int x = 5; int y = 4; MessageBox.Show((x+y).ToString());
35
List out 3 methods to convert string to numeric data types
1. int.Parse() 2. double.Parse() 3. decimal.Parse()
36
How to parse label value from string to int ?
int hoursWorked = int.Parse(hoursWorkedTextBox1.Text);
37
What will happen when the hoursWorkedTextBox1 has value of "49.99"? int hoursWorked = int.Parse(hoursWorkedTextBox1.Text);
1. Catch FormatException error * To solve this error, we can use Int.TryParse or double.TryParse ``` double hoursWorked; if (double.TryParse(hoursWorkedTextBox1.Text, out hoursWorked)) { MessageBox.Show("You entered: " + hoursWorked); } else { MessageBox.Show("Please enter a valid number."); } ```
38
What method is being used to display numeric values?
1. .ToString() method
39
How to show int myNumber = 123 to message box?
int myNumber = 123; MessageBox.Show(myNumber.ToString()); * Will get cannot convert from 'int' to 'string' when .ToString() isn't with myNumber in MessageBox
40
Use ToString() method to show number 12.3 with result 12.300
double x = 12.3; MessageBox.Show(x.ToString(**"n3"**)); * Use "n3" inside .ToString()
41
Use ToString() method to show number 123 with result 123.00
int x = 123; MessageBox.Show(x.ToString(**"f2"**)); * Use "f2" inside .ToString()
42
Use ToString() method to show number 123456.0 with result 1.235e+005
double x = 12.3; MessageBox.Show(x.ToString(**"e3"**)); * Use "e3" inside .ToString()
43
Use ToString() method to show number -12.3 with result ($12.3)
double x = 12.3; MessageBox.Show(x.ToString(**"C"**)); * Use "C" inside .ToString()
44
Use ToString() method to show number .234 with result 23.40%
double x = .234; // Same as 0.234 MessageBox.Show(x.ToString(**"P"**)); * Use "P" inside .ToString()
45
What is the difference between GroupBoxes and Panels
1. A panel cannot display a title and does not have a Text property, but a GroupBox supports these 2 properties 2. A panel's border can be specified by its BorderStyle property, while the GroupBox cannot be
46
What property is similar to the Image property of a PictureBox?
1. BackgroundImage
47
List out 3 tabs that Windows Form Application provides for Colors
1. Web 2. System 3. Custom
48
How to create a access key for buttons? I want press Alt + E to close the page
1. Go to Text property and type &Exit 2. Then add code ``` public void exitButton_Click (object sender, EventArgs e ) { this.Close(); } ```
49
List out 2 predefined constants that the Math Class provide
1. Math.PI 2. Math.E
50
How to use math class square root?
1. Math.Sqrt(x);
51
How to use math class power?
1. Math.Pow(x,y) x = 2 , y = 3 will be 2³ = 8
52
What is an exception?
1. Is an unexpected error that happens while a program is running * Will abruptly halt if an exception is not handled by the program
53
What code is used for exception handling?
try {} catch {}
54
How to try parse text box input of age from string into int?
``` try { int age; age = int.Parse(txtAge.Text); } catch { MessageBox.Show("Invalid Value Entered") } ```
55
How to create a constant value of my birth year 2003?
const int myBirthYear = 2003; * a constant variable represents a value that cannot be changed during the program's execution
56
How to declare variables as fields so that every method can use that value?
``` public partial class Form1: { private string name = "Jack"; public Form1() { InitializeComponent(); } private void showNameButton_Click(object sender, EventArgs e) { MessageBox.Show(name); } private void chrisButton_Click(object sender, EventArgs e) { name="Chris"; } } ``` * Think of Fields as **Global Variable** inside this class
57
How to show message box with the requirement below 1. Title : Logout 2. Description : Are you sure ? 3. Icon : Question Mark 4. Button : With Ok and Cancel
``` MessageBox.Show("Are you sure?" , "Logout" , MessageBoxButtons.OkCancel, MessageBoxIcon.Question); ```
58
List out all 6 relational operators
1. > - Greater than 2. < - Less than 3. >= - Greater than or equal to 4. <= - Less than or equal to 5. == - Equal to 6. != - Not equal to
59
Write a program to receive temperature from numeric up down with the conditions 1. >= 40 is Hot 2. < 40 and >= 10 is Ok 3. < 10 is Cold
``` int temp = (int) numTemp.Value; if ( temp >= 40 ) { MessageBox.Show("Hot"); } else if ( temp < 40 && temp >= 10 ) // or ( temp >= 10 ) is enough { MessageBox.Show("Ok"); } else { MessageBox.Show("Cold"); } ```
60
List out 3 logical operator
1. && - And 2. || - Or 3. ! - Not
61
Write a program to receive months from numeric up down with showing the correct month ( 1 - January )
``` int month_num = ( int ) numMonth.Value ; switch ( month_num ) { case 1: MessageBox.Show("January"); break; case 2: MessageBox.Show("February"); break; case 3: MessageBox.Show("March"); break; case 4: MessageBox.Show("April"); break; case 5: MessageBox.Show("May"); break; case 6: MessageBox.Show("June"); break; case 7: MessageBox.Show("July"); break; case 8: MessageBox.Show("August"); break; case 9: MessageBox.Show("September"); break; case 10: MessageBox.Show("October"); break; case 11: MessageBox.Show("November"); break; case 12: MessageBox.Show("December"); break; default: MessageBox.Show("No month found"); break; } ``` * Break statement in every case is a must or it will run all statement at each case * Another method using Array ``` string[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; int monthIndex = (int)numMonth.Value; // 1 through 12 if (monthIndex >= 1 && monthIndex <= 12) { MessageBox.Show(months[monthIndex - 1]); } else { MessageBox.Show("No month found"); } ```
62
Write a program to compare if 2 name is the same using String.Compare
``` string name1 = "Mary"; string name2 = "Mark"; if ( String.Compare(name1, name2) == 0 ) { MessageBox.Show("Both are the same name") } else { MessageBox.Show("Both name are not the same") } ``` * String.Compare **returns 0** when the two strings are exactly equal. * For case sensitive checking ``` String.Compare(name1, name2, StringComparison.OrdinalIgnoreCase) == 0 ```
63
What is the boolean variable called when is being used inside if statement? ``` bool grandMaster = false; if (grandMaster) { powerLevel += 500; //powerLevel = powerLevel +500; } if (!grandMaster) { powerLevel = 100; } ```
1. Flags
64
Write a program to use int.TryParse to return age from textbox
int age; if ( int.TryParse(inputAge.Text , out age) ) { MessageBox.Show($"You are {age} years old") } else { MessageBox.Show("Invalid age input") } * Also have **double.TryParse()** and **decimal.TryParse()**
65
What is input validation?
1. Process of inspecting data that has been entered into a program to make sure it is valid before it is used if ( textScore >= 0 && textScore <= 100 )
66
What is the difference between Radio Buttons and Check Boxes?
1. Radio buttons can only choose one from several possible choices, while Check Boxes can select multiple options
67
Write a program to check if the radio button male or female is pressed, then return text Male and Female
``` if ( rdrMale.Checked ) { MessageBox.Show("Male"); } else if ( rdrFemale.Checked ) { MessageBox.Show("Female"); } ``` or ``` MessageBox.Show(rdrMale.Text); ```
68
What event is when the checked property changes?
1. CheckedChanged
69
Write a program to add items to list box (listBoxFruits) when the program is first loaded then print out the fruit when user had press the btnShowSelected
``` private void Form1_Load(object sender, EventArgs e) { // Add items to the ListBox when the form loads listBoxFruits.Items.Add("Apple"); listBoxFruits.Items.Add("Banana"); listBoxFruits.Items.Add("Cherry"); listBoxFruits.Items.Add("Durian"); listBoxFruits.Items.Add("Elderberry"); } private void btnShowSelected_Click(object sender, EventArgs e) { // Check if an item is selected if (listBoxFruits.SelectedItem != null) { MessageBox.Show($"You selected: {listBoxFruits.SelectedItem.ToString()}"); } else { MessageBox.Show("Please select a fruit first!"); } } ``` ``` if ( listBoxFruit.SelectedIndex == -1 ) { MessageBox.Show("Nothing Selected") } ``` ``` listBoxFruits.Items.Clear(); ```
70
Write a program to print Hello 5 times
``` for ( int i = 0 ; i < 5 ; i ++ ) { MessageBox.Show("Hello") } ```
71
How to show 1 to 100 using for loop?
``` for ( int i = 1 ; i <= 100 ; i++ ) { MessageBox.Show(i.ToString()); } ```
72
How to show 100 to 1 using for loop?
``` for ( int i = 100 ; i <= 1 ; i-- ) { MessageBox.Show(i.ToString()); } ```
73
List out 2 pretest loops
1. for loop 2. while loop
74
List out posttest loop
1. do-while loop
75
Write a program using while loop to show Hello 5 times
``` int i = 0 ; while ( i < 5 ){ MessageBox.Show("Hello"); i++ ; } ``` Omitting i ++ will be showing **Hello** Infinitely
76
Until Slide 16