Vidyalelo
C# Programming · all questions

Functions and Methods in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

54

Questions

3/3

Page

Pick an option on a question to see the right answer and solution.

What is the return type of the IndexOf() method when applied to a string in C#?

Select an option to see the answer and solution.

What is the purpose of the params keyword in C# method parameters?

Select an option to see the answer and solution.

In C#, which keyword is used to exit from a method without returning any value?

Select an option to see the answer and solution.

What is the correct syntax to define a method named GetMax that takes two integer parameters num1 and num2 and returns the maximum of the two numbers in C#?

Select an option to see the answer and solution.

Which of these methods is executed first before execution of any other thing that takes place in a program?

Select an option to see the answer and solution.

Which of these can be used to differentiate two or more methods having same name?

Select an option to see the answer and solution.

Which of these data types can be used for a method having a return statement in it?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class box
{
    public  int width;
    public int height;
    public int length;
    public  int volume1;
    public void volume()
    {
        volume1 = width * height * length;
    }
    public void volume(int x)
    {
        volume1 = x;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        box obj = new box();
        obj.height = 1;
        obj.length = 5;
        obj.width = 5;
        obj.volume(5);
        Console.WriteLine(obj.volume1);        
        Console.ReadLine();
    }
}
a) 0

Select an option to see the answer and solution.

Which of these data types can be used for a method having a return statement in it?

Select an option to see the answer and solution.

What is the process of defining more than one method in a class differentiated by parameters known as?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class Program
{
    static void Main(string[] args)
    {
        int x, y = 1;
        x = 10;
        if(x != 10 && x / Convert.ToInt32(0) == 0)
        Console.WriteLine(y);
        else
        Console.WriteLine(++y);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class equality
{
    public  int x;
    public int y;
    public Boolean isequal()
    {
        return (x == y);
    }
}    
class Program
{
    static void Main(string[] args)
    {
        equality obj = new equality();
        obj.x = 5;
        obj.y = 5;
        Console.WriteLine(obj.isequal());
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
class box 
{
    int width;
    int height;
    int length;
    int volume;
    void volume(int height, int length, int width) 
    {
        volume = width * height * length;
    } 
}    
class Prameterized_method
{
    public static void main(String args[]) 
    {
       box obj = new box();
       obj.height = 1;
       obj.length = 5;
       obj.width = 5;
       obj.volume(3, 2, 1);
       Console.WriteLine(obj.volume);  
       Console.ReadLine();      
    } 
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class equality 
{
    int x;
    int y;
    boolean isequal()
    {
        return(x == y);  
    } 
}    
class Output 
{
    public static void main(String args[]) 
    {
       equality obj = new equality();
       obj.x = 5;
       obj.y = 5;
       Console.WriteLine(obj.isequal());
    } 
}

Select an option to see the answer and solution.