What is the purpose of method parameters in C#?
A. To define the name of the method
B. To specify the return type of the method
C. To define the access modifier of the method
D. To pass data to the method
Select an option to see the answer and solution.
What is the result of the expression Math.Round(4.5) in C#?
Select an option to see the answer and solution.
What is the correct syntax to declare a method named PrintMessage that prints a message to the console without returning any value in C#?
A. PrintMessage: { Console.WriteLine("Message"); }
B. void PrintMessage { Console.WriteLine("Message"); }
C. PrintMessage() { Console.WriteLine("Message"); }
D. void PrintMessage() { Console.WriteLine("Message"); }
Select an option to see the answer and solution.
In C#, which keyword is used to define a method that cannot be overridden in derived classes?
A. final
B. static
C. sealed
D. const
Select an option to see the answer and solution.
What is the purpose of method overloading in C#?
A. To allow methods with the same name and signature
B. To override existing methods
C. To allow methods with the same name but different signatures
D. To restrict access to methods
Select an option to see the answer and solution.
What is the correct way to declare a method named GetAbsoluteValue that takes an integer parameter num and returns its absolute value in C#?
A. GetAbsoluteValue(num) { return Math.Abs(num); }
B. int GetAbsoluteValue(int num) { return Math.Abs(num); }
C. GetAbsoluteValue { return Math.Abs(num); }
D. None of the above
Select an option to see the answer and solution.
In C#, which method is used to convert a string representation of a number to its integer equivalent?
A. string.ToInt()
B. Math.ToInt()
C. int.Parse()
D. Convert.ToInt32()
Select an option to see the answer and solution.
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#?
A. double CalculateArea(double length, double width) { return length * width; }
B. CalculateArea(double length, double width) { return length * width; }
C. double CalculateArea(length, width) { return length * width; }
D. CalculateArea { double length * double width; }
Select an option to see the answer and solution.
In C#, which keyword is used to define a method that can be overridden in derived classes?
A. virtual
B. overridable
C. extendable
D. override
Select an option to see the answer and solution.
What is the correct way to call a method named PrintName with a string parameter name in C#?
A. PrintName("John");
B. PrintName(name: "John");
C. PrintName = "John";
D. PrintName(name);
Select an option to see the answer and solution.
What is the purpose of method parameters in C#?
A. To define the return type of the method
B. To specify the name of the method
C. To pass data to the method
D. To specify the access modifier of the method
Select an option to see the answer and solution.
Which of the following access modifiers allows a method to be accessed only within the same assembly in C#?
A. internal
B. private
C. protected
D. public
Select an option to see the answer and solution.
What is the result of the expression Math.Floor(4.6) in C#?
Select an option to see the answer and solution.
What is the correct way to define a method named IsEven that takes an integer parameter num and returns true if the number is even, otherwise false, in C#?
A. IsEven(num) { return num % 2 == 0; }
B. bool IsEven = (int num) => num % 2 == 0;
C. bool IsEven(int num) { return num % 2 == 0; }
D. bool IsEven { return num % 2 == 0; }
Select an option to see the answer and solution.
In C#, which keyword is used to define a method that is implemented in a derived class to provide a specific implementation for a method defined in the base class?
A. abstract
B. override
C. implement
D. None of the above
Select an option to see the answer and solution.
What is the correct way to declare a method named PrintMessage that prints a message to the console without taking any parameters or returning any value in C#?
A. PrintMessage: { Console.WriteLine("Message"); }
B. void PrintMessage { Console.WriteLine("Message"); }
C. void PrintMessage() { Console.WriteLine("Message"); }
D. PrintMessage() { Console.WriteLine("Message"); }
Select an option to see the answer and solution.
In C#, which method is used to convert a string to its uppercase equivalent?
A. ToUpperString()
B. UpperCase()
C. ConvertToUpperCase()
D. ToUpper()
Select an option to see the answer and solution.
What is the purpose of method overloading in C#?
A. To restrict access to methods
B. To allow multiple methods with the same parameters
C. To allow multiple methods with the same name but different parameters
D. To allow multiple methods with the same name
Select an option to see the answer and solution.
What is the correct syntax to define a method named CalculateAverage that calculates the average of an array of integers in C#?
A. CalculateAverage(numbers[]) { return numbers.Average(); }
B. double CalculateAverage(numbers[]) { return numbers.Average(); }
C. CalculateAverage(int[] numbers) { return numbers.Average(); }
D. double CalculateAverage(int[] numbers) { return numbers.Average(); }
Select an option to see the answer and solution.
In C#, which keyword is used to define a method that cannot be overridden in derived classes?
A. sealed
B. static
C. override
D. const
Select an option to see the answer and solution.