c# - 如何在 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];
解决方案
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]);
}
}
}
推荐阅读
- c# - 不同的列表
- >
- angular - 如何在 Angular 服务中正确检索和缓存数据
- kubernetes - 我可以在 Kubernetes 中根据命名空间安排工作负载吗?
- python - 在 Python 中查找嵌套列表的索引
- html - 每个页面的特定表格更改的 X 路径和 CSS 选择器
- sql - 追踪 30 天的汇总和案例逻辑
- python - 'NoneType' 对象没有属性 'user' Django
- python - Pycrytpo 和 mySQL 问题
- java - 日历日中 2 个瞬间之间的差异
- c - 有什么方法可以将 _Static_assert 放入 ISO C11 中的表达式中?