C#多维数组(2D)分配的内存足够多

时间:2018-06-12 17:04:55

标签: c# multidimensional-array

所以我正在分配@RunWith(PowerMockRunner.class) @PrepareForTest(TestService.class) public class TestServiceTest { @Mock private TestService<Subscription> testServiceProxy; @Mock private Subscription subscription; @Test public void testStart() throws Exception { Integer id = new Integer(5); PowerMockito.mockStatic(TestService.class); PowerMockito.when(TestService.getString()).thenReturn("Hello!"); PowerMockito.when(testServiceProxy.getInt()).thenReturn(new Integer(15)); PowerMockito.when(TestService.function1(Subscription.class,id)).thenReturn(testServiceProxy); // PowerMockito.when(TestService.function1(Subscription.class,Matchers.eq(any(Integer.class)))).thenReturn(testServiceProxy); System.out.println("String: " + TestService.getString()); System.out.println("TestServiceProxy: "+testServiceProxy); // id = new Integer(6); System.out.println("Function1: "+TestService.function1(Subscription.class, id)); TestService<Subscription> foo = TestService.function1(Subscription.class, id); if (foo != null) { System.out.println(" foo instrumentId: "+foo.getInt()); System.out.println(" subselect instrumentId: "+testServiceProxy.getInt()); } else { System.out.println("Foo is null"); } } } 。但是在调试时我发现我的矩阵有[0,0] [0,1]。(插槽)为什么会这样?我有2个值的插槽?不应该只有1吗? (别告诉我,我必须使用一维数组,这只是一个例子)。如果我想声明一个3乘2的矩阵(只有3个可能的行)[0,0],[0,1],[0,2]我应该怎么做?

2 个答案:

答案 0 :(得分:1)

数组始终以索引0开始

所以

[0,0] =维度1值1 [0,1] =维度1值2

编辑:

如果您想要1维中的3个值,则必须执行

int [,] matrix = new int [1,3];

我希望它对你有帮助吗?

答案 1 :(得分:0)

我猜你以某种方式感到困惑。

显然1 x 2 matrix有2个广告位。

如果您只需要1个广告位,则为1 x 1 matrix

示例:

enter image description here

希望有所帮助