首页 > 解决方案 > 如何在 C# 中创建 Matlab 的单元结构?

问题描述

我想在 C# 中创建自己的数据类型,就像 Matlab 的单元结构一样。请参阅以下示例。

a{1,1}=[1 2 3; 4 5 6];

a{1,2}=[3 2 3; 3 1 6];

a{2,1}=[0 2 5; 4 1 6];

a{2,2}=[0 2 1; 4 4 4];

标签: c#

解决方案


I found the following solution (using different matrices):

using System;

namespace jagged_array_learning
{
class Program
{
    static void Main(string[] args)
    {

        int[,] m1 = new int[2,2];
        int[,] m2 = new int[2,2];
        int[,] m3 = new int[2,2];
        int[,] m4 = new int[2,2];

        m1[0,0] = 1;
        m1[0,1] = 2;
        m1[1,0] = 3;
        m1[1,1] = 4;

        m2[0,0] = 5;
        m2[0,1] = 6;
        m2[1,0] = 7;
        m2[1,1] = 8;

        m3[0,0] = 9;
        m3[0,1] = 10;
        m3[1,0] = 11;
        m3[1,1] = 12;

        m4[0,0] = 13;
        m4[0,1] = 14;
        m4[1,0] = 15;
        m4[1,1] = 16;

        int[,][,] a = new int[2,2][,];

        a[0,0] = m1;
        a[0,1] = m2;
        a[1,0] = m3;
        a[1,1] = m4;


        Console.WriteLine(a[0,1][1,0]);




    }
}

}


推荐阅读