C# Arrays Aptitude Questions and Answers | Set 3

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

1) What is the correct way to access each element of an array without using an index variable?
  1. Using do-while loop
  2. Using for loop
  3. Using while loop
  4. Using a foreach loop

2) There are the following options are given below, which of them are the correct way to initialize an array of three integers?
  1. int []arr;
    arr = new int[3];
    arr[0]=1;
    arr[1]=1;
    arr[2]=1;
    
  2. int []arr = {1,2,3};
    
  3. int []arr;
    arr = new int {1,2,3};
    
  4. int []arr;
    arr = new int[3] {1,2,3};
    

Options:

  1. Only A
  2. Only B
  3. Only D
  4. A, B, D

3) What is the correct output of given code snippets?
static void Main(string[] args)
{
	int[] ARR = {1,2,3,4,5};

	foreach (int X in ARR)
	{
		Console.Write(X + " ");
	}
}
  1. 1 2 3 4 5
  2. 0 0 0 0 0
  3. Syntax Error
  4. Runtime Exception

4) If we created an array of 5 integers, can we increase array size from 5 to 10?
  1. Yes
  2. No

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	int[] ARR = {1,2};

	ARR = new int[4];

	foreach (int X in ARR)
	{
		Console.Write(X + " ");
	}
}
  1. 1 2 0 0
  2. 0 0 0 0
  3. Syntax Error
  4. Runtime Error



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.