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

Parameters and arguments 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 that takes one integer parameter.

C Sharp (C#)
void PrintNumber([1] number) {
    Console.WriteLine(number);
}
Drag options to blanks, or click blank then click option'
Abool
Bstring
Cint
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to specify the type of the parameter.
Using a wrong type that doesn't match the argument.
2fill in blank
medium

Complete the code to call the method with an argument.

C Sharp (C#)
PrintNumber([1]);
Drag options to blanks, or click blank then click option'
A5
B"5"
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer.
Passing a boolean or null where an integer is expected.
3fill in blank
hard

Fix the error in the method declaration by completing the parameter list.

C Sharp (C#)
void Greet([1] name) {
    Console.WriteLine($"Hello, {name}!");
}
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cbool
Ddouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using a numeric type for a text parameter.
Forgetting to specify the parameter type.
4fill in blank
hard

Fill both blanks to declare a method with two parameters and call it with matching arguments.

C Sharp (C#)
void AddNumbers([1] a, [2] b) {
    Console.WriteLine(a + b);
}

AddNumbers(3, 4);
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cbool
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different types for parameters.
Using non-numeric types for addition.
5fill in blank
hard

Fill all three blanks to declare a method with parameters and call it with arguments.

C Sharp (C#)
void DisplayInfo([1] name, [2] age) {
    Console.WriteLine($"Name: {name}, Age: {age}");
}

DisplayInfo([3], 30);
Drag options to blanks, or click blank then click option'
Astring
Bint
C"Alice"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong types as arguments.
Forgetting quotes around string arguments.