Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a method named Add that takes two integers and returns their sum.
C Sharp (C#)
public int Add(int a, int b) {
return a [1] b;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + will subtract instead of add.
Using * or / will multiply or divide, not add.
✗ Incorrect
The plus sign (+) adds two integers together in C#.
2fill in blank
mediumComplete the code to overload the Add method to accept two double values.
C Sharp (C#)
public double Add(double a, double b) {
return a [1] b;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - will subtract instead of add.
Using * or / will multiply or divide instead of add.
✗ Incorrect
The plus sign (+) adds two double values in C#.
3fill in blank
hardFix the error in the overloaded Add method that takes three integers.
C Sharp (C#)
public int Add(int a, int b, int c) {
return a [1] b [2] c;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different operators between numbers causes errors or wrong results.
Using only one operator and missing the other causes syntax errors.
✗ Incorrect
Use the plus sign (+) to add all three integers together.
4fill in blank
hardComplete the code to overload the Add method to accept two strings and concatenate them.
C Sharp (C#)
public string Add(string a, string b) {
return a [1] b;;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - or * instead of + will cause errors.
Missing the semicolon causes syntax errors.
✗ Incorrect
Use + to join strings and ; to end the statement.
5fill in blank
hardFill all three blanks to overload the Add method to accept an array of integers and return their sum.
C Sharp (C#)
public int Add(int[] numbers) {
int sum = 0;
foreach (int [1] in numbers) {
sum [2]= [3];
}
return sum;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using '-' instead of '+=' causes wrong results.
✗ Incorrect
Use 'num' as the loop variable, '+=' to add to sum, and 'num' as the value to add.