微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 C# 代码段转换为二维数组的 Dart

如何解决将 C# 代码段转换为二维数组的 Dart

我是 dart 编程的新手。我正在尝试将 C# 中的以下代码片段转换为 Dart。但是,我对能够移植二维数组的实现感到困惑。任何提示解决方案都会有所帮助。

public static byte[][] GetRfidBlock(byte[] arr)
        {
            int numblocks = ((arr.Length - 1) / 4) + 1;
            //byte[][] ret = new byte[numblocks][4];
            byte[][] ret = new byte[numblocks][];

            int ctr = 0;
            int ctr4 = 0;
            int ctr1stdim = 0;
            ret[ctr1stdim] = new byte[4];
            while (ctr < arr.Length)
            {
                ret[ctr1stdim][ctr4++] = arr[ctr++];
                if (ctr4 == 4)
                {
                    ctr4 = 0;
                    ctr1stdim++;
                    ret[ctr1stdim] = new byte[4];
                }
            }
            return ret;
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。