0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#:2次元配列の解説

Posted at
スクリーンショット 2020-03-23 9.51.49.png
Sample.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 2次元配列
// * Table/表

public class Sample : MonoBehaviour
{
    // 宣言方法
    // 1次元配列
    int[] arrayInt = new int[3];
    // 2次元配列
    int[,] tabelInt = new int[3, 2];
    void Start()
    {
        // 代入方法
        tabelInt[0, 0] = 1;
        tabelInt[2,1] = 10;
        // 取得方法
        //int x = tabelInt[0, 0];

        //長さ
        //Debug.Log(arrayInt.Length);
        Debug.Log(tabelInt.GetLength(0));
        Debug.Log(tabelInt.GetLength(1));
        for (int x = 0; x<tabelInt.GetLength(0); x++)
        {
            for (int y = 0; y < tabelInt.GetLength(1); y++)
            {
                Debug.Log(tabelInt[x,y]);
            }
        }
        for (int y = 0; y < tabelInt.GetLength(1); y++)
        {
            for (int x = 0; x < tabelInt.GetLength(0); x++)
            {
                Debug.Log(tabelInt[x, y]);
            }
        }
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?