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

Method declaration and calling 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 Greet that prints a message.

C Sharp (C#)
void [1]() {
    Console.WriteLine("Hello!");
}
Drag options to blanks, or click blank then click option'
AGreet
BPrint
CSayHello
DMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name different from the one asked.
Leaving the method name blank.
2fill in blank
medium

Complete the code to call the method named Greet.

C Sharp (C#)
class Program {
    static void Main() {
        [1]();
    }
}
Drag options to blanks, or click blank then click option'
AMessage
BPrint
CGreet
DSayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a method with a wrong name.
Forgetting the parentheses when calling the method.
3fill in blank
hard

Fix the error in the method declaration by completing the missing return type.

C Sharp (C#)
[1] Greet() {
    Console.WriteLine("Hello!");
}
Drag options to blanks, or click blank then click option'
Avoid
Bint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using a return type other than void without returning a value.
Leaving the return type blank.
4fill in blank
hard

Fill both blanks to declare a method named Add that returns the sum of two integers a and b.

C Sharp (C#)
static [1] Add(int a, int b) {
    return a [2] b;
}
Drag options to blanks, or click blank then click option'
Aint
B+
C-
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type when returning a value.
Using subtraction instead of addition.
5fill in blank
hard

Fill all three blanks to declare and call a method named Multiply that returns the product of two integers x and y.

C Sharp (C#)
static [1] Multiply(int x, int y) {
    return x [2] y;
}

static void Main() {
    int result = Multiply([3], 5);
    Console.WriteLine(result);
}
Drag options to blanks, or click blank then click option'
Aint
B*
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type.
Using wrong operator.
Passing wrong argument value.