0
0
C Sharp (C#)programming~10 mins

Method overloading in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A*
B-
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + will subtract instead of add.
Using * or / will multiply or divide, not add.
2fill in blank
medium

Complete 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using - will subtract instead of add.
Using * or / will multiply or divide instead of add.
3fill in blank
hard

Fix 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'
A*
B-
C+
D/
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.
4fill in blank
hard

Complete 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'
A+
B-
C;
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using - or * instead of + will cause errors.
Missing the semicolon causes syntax errors.
5fill in blank
hard

Fill 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'
Anum
B+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using '-' instead of '+=' causes wrong results.