c++ ##_##_C#数组能力问题和解答 套装2

c++ ##_##

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

Answer & Explanation

Correct answer: 2
12

In the above code snippet, we are creating a 3-Dimensional array, then the length of the array will be 2 x 2 x 3 = 12

1)给定代码段的正确输出是什么?
  1. 7

  2. 12

  3. 18

  4. 8

答案与解释

正确答案:2
12

在上面的代码片段中,我们创建了一个3维数组,那么数组的长度将为2 x 2 x 3 = 12

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

Answer & Explanation

Correct answer: 1
It will create a 3-D jagged array that contains 2 2-D jagged arrays.

The first option is correct about the above code.

2)以下代码将创建什么?
  1. 它将创建一个包含2个2D锯齿阵列的3D锯齿阵列。

  2. 它将创建一个包含3个2D锯齿阵列的3D锯齿阵列。

  3. 它将创建一个包含两个2D锯齿阵列的2D锯齿阵列

  4. 无效的代码

答案与解释

正确答案:1
它将创建一个包含2个2D锯齿阵列的3D锯齿阵列。

关于上述代码,第一个选项是正确的。

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;

Answer & Explanation

Correct answer: 3
arr.Length;

The Length property is used to get the total number of elements in an array.

3)在给定数组中查找元素总数的正确方法是什么?
  1. arr.TotalItems();

  2. arr.ItemsCount();

  3. 长度

  4. 数量

答案与解释

正确答案:3
长度

Length属性用于获取数组中元素的总数。

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

Answer & Explanation

Correct answer: 3
0

In C#.NET, 0 is the default value of array elements.

4)如果我们不分配整数数组中的值,默认的整数数组元素将是什么?
  1. 1个

  2. ' ' (空间)

  3. 0

  4. -1

答案与解释

正确答案:3
0

在C#.NET中,0是数组元素的默认值。

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

Answer & Explanation

Correct answer: 1
0,2,0,4,0

In the code, only index 1 and 3 are assigned with the 2 and 4, rest all elements contain the default values (0).

5)给定代码段的正确输出是什么?
  1. 0,2,0,4,0

  2. 1,2,3,4,5

  3. -1,2,-1,4,-1

  4. 0,0,0,0

答案与解释

正确答案:1
0,2,0,4,0

在代码中,只有索引1和3被分配了2和4,其余所有元素都包含默认值(0)。

翻译自: https://www.includehelp.com/dot-net/csharp-arrays-aptitude-questions-and-answers-2.aspx

c++ ##_##

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值