【问题标题】:How to briefly declare multiple byte arrays in c#如何在c#中简要声明多个字节数组
【发布时间】:2019-02-18 13:46:37
【问题描述】:

例如,我想声明以下内容,但希望有一个简单的方法。然后分别使用它们中的每一个:

$byte[] image_bt_update_1 = null;
$byte[] image_bt_update_2 = null;
$byte[] image_bt_update_3 = null;
$byte[] image_bt_update_4 = null;

【问题讨论】:

  • $byte [] 不是有效的 c# 代码 - $byte不是有效类型。
  • 没有必要用null“初始化”它们。如果只写byte[] someArray;null已经是默认值了。

标签: c# byte declare


【解决方案1】:

如果你使用 C#,你可以使用数组数组

byte[][] image_tb_update = new byte[4][_N];

其中 _N 是 image_tb_update 数组的维度

并将其称为

image_tb_update[0][0]... image_tb_update[0][_N-1]
image_tb_update[3][0]... image_tb_update[3][_N-1]

初始化所有元素

for (int i=0;i<3;i++)
   for (int j=0;i<_N;j++)
      image_tb_update[i][j]=0;

【讨论】:

    【解决方案2】:

    由于它们是相同的类型,您可以将它们替换为:

    $byte[] image_bt_update_1 = null, image_bt_update_2 = null, image_bt_update_3 = null, image_bt_update_4 = null;

    【讨论】:

      猜你喜欢
      • 2013-04-11
      • 2014-07-23
      • 2014-10-17
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多