Functions And Methods In C Sharp - Study Mode
[#31] In C#, which keyword is used to define a method that belongs to a class and can be called without creating an instance of the class?
Correct Answer
(A) static
[#32] What is the correct syntax to declare a method named PrintMessage that prints a message to the console without returning any value in C#?
Correct Answer
(D) void PrintMessage() { Console.WriteLine("Message")
}
[#33] What is the correct way to declare a method named GetAbsoluteValue that takes an integer parameter num and returns its absolute value in C#?
Correct Answer
(B) int GetAbsoluteValue(int num) { return Math.Abs(num)
}
[#34] What is the correct syntax to define a method named CalculateArea that calculates the area of a rectangle with length and width parameters in C#?
Correct Answer
(B) CalculateArea(double length, double width) { return length * width
}
[#35] What is the correct way to call a method named PrintName with a string parameter name in C#?
Correct Answer
(B) PrintName(name: "John")