This set of C# Questions and Answers for Experienced people focuses on “Use of Variable Number of Arguments”.
1. The method in which large or variable number of arguments are handled is known as ________________
a) Value parameters
b) Output parameters
c) Parameter arrays
d) None of the mentioned
View Answer
Explanation: None.
2. The modifiers used to define an array of parameters or list of arguments is __________
a) ref
b) out
c) param
d) var
View Answer
Explanation: None.
3. What will be the output of the following C# code?
static void Main(string[] args)
{
object[] a = {" 1 ", 4.0f, " harsh "};
fun(a);
Console.ReadLine();
}
static void fun(params object[] b)
{
for (int i = 0; i < b.Length - 1; i++)
Console.WriteLine(b[i] + " ");
}
a) 1 4.0 harsh
b) 1 4
c) 1 4 hars
d) 1 4 harsh
View Answer
Explanation: ‘a’ is declared as array of objects which is passed as a parameter to a single method fun() using variable number of parameters.
Output :
1 4 harsh
4. Which of the following statements are correct?
a) C SHARP allows a function to have arguments with default values
b) C SHARP allows a function to have variable number of arguments
c) Params are used to specify the syntax for a function having arguments
d) Omitting the return value type in method definition results into an exception
View Answer
Explanation: None.
5. What will be the output of the following C# code?
static void Main(string[] args)
{
int [] a = {1, 2, 3, 4, 5};
fun(a);
Console.ReadLine();
}
static void fun(params int[] b )
{
int[] k = { 3, 4, 7, 8,'\0' };
for (int i = 0; i < b.Length; i++)
{
b[i] = b[i] + k[i] ;
Console.WriteLine( b[i] + " ");
}
}
a) Compile time error
b) 3, 4, 7, 8, 5
c) 3, 4, 7, 8, 5, 1, 2, 3, 4, 5
d) 4, 6, 10, 12, 5
View Answer
Explanation: Passing of array parameters declared in main() and hence adding elements of array passed using param to another array k[] declared in fun() method.
Output :
4, 6, 10, 12, 5
6. What will be the output of the following C# code?
static void Main(string[] args)
{
int [] a = {1, 2, 3, 4, 5};
fun(a);
Console.ReadLine();
}
static void fun(params int[] b )
{
for (int i = 0; i < b.Length; i++)
{
b[i] = b[i] * 5 ;
Console.WriteLine(b[i] + "");
}
}
a) 1, 2, 3, 4, 5
b) 5, 10, 15, 20, 25
c) 5, 25, 125, 625, 3125
d) 6, 12, 18, 24, 30
View Answer
Explanation: None.
Output :
5, 10, 15, 20, 25
7. What will be the output of the following C# code?
static void Main(string[] args)
{
int[] a = {2, 21, 34, 46, 85, 88, 90};
fun(a);
Console.ReadLine();
}
static void fun(params int[] b)
{
int[] c = {1, 2, 3, 4, 5, 6, 7};
int i, j = 0;
for (i = 0; i < b.Length; i++)
if (b[i] % 2 == 0)
{
c[j++] = b[i];
}
for (i = 0; i < j; i++)
{
Console.Write(c[i] + " ");
}
}
a) Compile time error
b) 2, 21, 34, 4, 6, 46, 88, 90
c) 2, 4, 34, 46, 6, 88, 90
d) 2, 34, 46, 88, 90
View Answer
Explanation: The program is finding even numbers in a given array, storing it into another array and then displaying that to the console.
8. Select the correct declaration of the defining array of parameters.
a)
void func(int[] x) { }
b)
void func(int x) { }
c)
void func(param int[]) { }
d)
void fun(param int[] x) { }View Answer
Explanation: None.
9. What will be the output of the following C# code?
static void Main(string[] args)
{
int[] x = { 80, 82, 65, 72, 83, 67 };
fun(x);
Console.ReadLine();
}
static void fun(params int [] b )
{
int i;
for (i = 5; i >=0 ; i--)
{
Console.WriteLine(Convert.ToChar(b[i]));
}
}
a) 67 83 72 65 82 80
b) P R A H S C
c) C S H A R P
d) 80 82 65 72 83 67
View Answer
Explanation: None.
10. What will be the output of the following C# code?
static void Main(string[] args)
{
int[] x = {65, 66, 67, 68, 69, 70};
fun(x);
Console.ReadLine();
}
static void fun(params int[] b )
{
int i;
for (i = 5; i > 0 ; i--)
{
b[i] = b[i] + 32;
Console.WriteLine(Convert.ToChar(b[i]));
}
}
a) A, B, C, D, E, F
b) F, E, D, C, B, A
c) f, e, d, c, b
d) b, c, d, e, f
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C# Programming Language.
Here’s the list of Best Books in C# Programming Language.
To practice all areas of C# for Experienced people, here is complete set on 1000+ Multiple Choice Questions and Answers on C#.
- Check MCA Books
- Practice MCA MCQs
- Apply for Computer Science Internship
- Apply for C# Internship
- Check C# Books