Home > Backend Development > C#.Net Tutorial > What is a jagged array in C#?

What is a jagged array in C#?

WBOY
Release: 2023-09-05 13:52:12
forward
1328 people have browsed it

C# 中的锯齿数组是什么?

Jagged array is an array of arrays in C#. You can declare and initialize it -

int[][] rank = new int[1][]{new int[]{5,3,1}};
Copy after login

The following example shows how to use jagged array in C#-

Example

using System;

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

         int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};
         int i, j;

         for (i = 0; i < 2; i++) {
            for (j = 0; j < 2; j++) {
               Console.WriteLine("a[{0}][{1}] = {2}", i, j, rank[i][j]);
            }
         }
         Console.ReadKey();
      }
   }
}
Copy after login

Output

Above, We have a jagged array of 2 integer arrays -

int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};
Copy after login

The above is the detailed content of What is a jagged array in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template