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

Method declaration and calling in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a method in C#?
A method is a block of code that performs a specific task. It can be called to run that task whenever needed.
Click to reveal answer
beginner
How do you declare a method that returns no value in C#?
Use the void keyword before the method name. For example: <br>
void SayHello() { Console.WriteLine("Hello!"); }
Click to reveal answer
beginner
How do you call a method named Greet in C#?
Simply write the method name followed by parentheses: <br>
Greet();
Click to reveal answer
beginner
What is the purpose of method parameters?
Parameters let you send information into a method so it can use that data to do its job.
Click to reveal answer
beginner
How do you declare a method that returns an integer value?
Specify the return type before the method name. For example: <br>
int GetNumber() { return 5; }
Click to reveal answer
Which keyword is used to declare a method that does not return any value?
Anull
Bint
Creturn
Dvoid
How do you call a method named DisplayMessage?
ADisplayMessage;
BDisplayMessage();
Cmethod DisplayMessage();
Dcall DisplayMessage;
What does a method parameter do?
ASends data into the method
BReturns data from the method
CStops the method
DNames the method
Which part of a method declaration specifies the type of value it returns?
AReturn type before the method name
BMethod name
CParameters inside parentheses
DMethod body inside braces
What happens if a method has a return type other than void?
AIt cannot be called
BIt cannot have parameters
CIt must return a value of that type
DIt must be static
Explain how to declare and call a simple method in C# that prints a message.
Think about the method header, body, and how you run it.
You got /5 concepts.
    Describe the role of parameters and return types in methods.
    Consider how methods communicate with the outside.
    You got /4 concepts.