【问题标题】:C# How can I put all my on off bools in a matrix and how can I control several at the same time?C# 如何将我所有的 on off bools 放在一个矩阵中,如何同时控制几个?
【发布时间】:2020-07-24 22:37:22
【问题描述】:

如何将我所有的开关布尔值放在一个矩阵中;以及如何同时控制多个?

我有 27 x 27 LED 灯。所以我需要一个带有 [27,27] 的矩阵以及如何: 我无法自行更改 LED 代码,因为它有自定义代码。我只想轻松地打开/关闭它们,这样我就可以在 LED 屏幕上制作箭头或微笑 :-)

示例控件

matrix[LED1 , LED9 , LED52] = true

    bool LED1 = false;
    bool LED2 = false;
    bool LED3 = false;

【问题讨论】:

    标签: c# matrix 2d matrix-multiplication


    【解决方案1】:

    您可以像这样将它们添加到数组中:

    bool[][] leds = new bool[27][];
    
    for (int i = 0; i < 27; i++) {
        leds[i] = new bool[27];
        
        for (int j = 0; j < 27; j++) {
            leds[i][j] = false;
        }
    }
    

    然后您可以像这样访问和更改值:

    leds[0][5] = true; //first index is the row, second index is the column
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      • 2016-10-09
      • 2022-07-29
      相关资源
      最近更新 更多