C# Arrays Aptitude Questions and Answers | Set 2

C# Arrays Aptitude Questions | Set 2: This section contains aptitude questions and answers on C# Arrays.
Submitted by Nidhi, on April 01, 2020

1) What is the correct output of given code snippets?
int [,,]arr = new int[2,2,3];
Console.WriteLine(arr.Length);
  1. 7
  2. 12
  3. 18
  4. 8

2) What will the following code create?
byte [][][]arr = new byte[2][][];
  1. It will create a 3-D jagged array that contains 2 2-D jagged arrays.
  2. It will create a 3-D jagged array that contains 3 2-D jagged arrays.
  3. It will create a 2-D jagged array that contains 2 2-D jagged arrays
  4. Invalid code

3) What is the correct way to find total number of elements in given array?
int []arr = {1,2,3,4,5};
  1. arr.TotalItems();
  2. arr.ItemsCount();
  3. arr.Length;
  4. arr.Count;

4) If we do not assign values in an integer array, what will be the default integer array elements?
  1. 1
  2. ' ' (Space)
  3. 0
  4. -1

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	int[] a = new int[5];

	a[1] = 2;
	a[3] = 4;

	Console.WriteLine(a[0] + "," + a[1] + "," + a[2] + "," + a[3] + "," + a[4]);
}
  1. 0,2,0,4,0
  2. 1,2,3,4,5
  3. -1,2,-1,4,-1
  4. 0,0,0,0





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.