Examveda

What will be the output of the following C# code?
static void Main(string[] args)
{
    Program p = new Program();
    p.display(2, 3, 8);
    int []a = { 2, 56, 78, 66 };
    Console.WriteLine("example of array");
    Console.WriteLine("elements added are");
    p.display(a);
    Console.ReadLine();
}
public void display(params int[] b)
{
    foreach (int i in b)
    {
        Console.WriteLine("ARRAY IS HAVING:{0}", i);
    }
}

A. Compile time error

B. Run time error

C. Code runs successfully but prints nothing

D. Code runs successfully and prints given on console

Answer: Option D


Join The Discussion

Related Questions on Arrays and Strings in C Sharp