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

Return values and void methods 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 make the method return an integer value.

C Sharp (C#)
public int GetNumber() {
    return [1];
}
Drag options to blanks, or click blank then click option'
Anull
B5
Ctrue
D"5"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a string instead of an integer.
Returning a boolean value.
Returning null in a method that expects int.
2fill in blank
medium

Complete the code to call the method and store its return value.

C Sharp (C#)
int result = [1]();
Drag options to blanks, or click blank then click option'
AGetNumber
BPrintNumber
CShowMessage
DDisplay
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a void method that does not return a value.
Using a method name that does not exist.
3fill in blank
hard

Fix the error in the method so it compiles correctly.

C Sharp (C#)
public void PrintMessage() {
    [1] "Hello!";
}
Drag options to blanks, or click blank then click option'
Areturn
Bint
CConsole.WriteLine
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using return in a void method without a value.
Declaring a type inside the method body.
4fill in blank
hard

Complete the code to create a method that returns the sum of two integers.

C Sharp (C#)
public int Sum(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 subtraction instead of addition.
Forgetting the semicolon at the end of the return statement.
5fill in blank
hard

Fill both blanks to create a method that returns the uppercase version of a string.

C Sharp (C#)
public string ToUpperCase(string input) {
    string result = input[1]();
    return [2];
    // End of method
}
Drag options to blanks, or click blank then click option'
A.ToUpper
Bresult
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses after ToUpper.
Returning the wrong variable.
Adding extra code after return statement.