C# 中交错数组的元素类型是什么?

C# 中交错数组的元素类型是什么?

交错数组是数组的数组,因此它的元素是引用类型并初始化为 null。

让我们看看如何使用交错数组 -

声明锯齿状数组 -

int [][] marks;

现在,让我们初始化它,其中marks是一个由5个整数组成的数组 -

int[][] marks = new int[][]{new int[]{ 40,57 },new int[]{ 34,55 }, new int[]{ 23,44 },new int[]{ 56, 78 }, new int[]{ 66, 79 } };

现在让我们看看 C# 中交错数组的完整示例,并了解如何实现它 -

示例

实时演示

using System;

namespace MyApplication {
   class MyDemoClass {
      static void Main(string[] args) {
         int i, j;
         int[][] marks = new int[][] {
            new int[] {
               90,
               95
            }, new int[] {
               89,
               94
            }, new int[] {
               78,
               87
            }, new int[] {
               76,
               68
            }, new int[] {
               98,
               91
            }
         };

         for (i = 0; i < 5; i++) {
            for (j = 0; j < 2; j++) {
               Console.WriteLine("marks[{0}][{1}] = {2}", i, j, marks[i][j]);
            }
         }
         Console.ReadKey();
      }
   }
}

输出

marks[0][0] = 90
marks[0][1] = 95
marks[1][0] = 89
marks[1][1] = 94
marks[2][0] = 78
marks[2][1] = 87
marks[3][0] = 76
marks[3][1] = 68
marks[4][0] = 98
marks[4][1] = 91

以上就是C# 中交错数组的元素类型是什么?的详细内容,更多请关注编程之家其它相关文章!

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

相关推荐