728x90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace starcraft
{
internal class App
{
//생성자
public App()
{
//정수형 2차원 배열 정의 및 배열의 인스턴스 생성
int[,] map = new int[3, 2];
//인덱스로 배열의 요소에 접근
map[2, 1] = 1;
//배열의 순회 (요소를 출력)
int rowLength = map.GetLength(0);
int colLength = map.GetLength(1);
//맵을 출력
for(int i = 0; i < rowLength; i++)
{
for(int j = 0; j < colLength; j++)
{
Console.Write("[{0},{1}] : {2}\t", i, j, map[i, j]);
}
Console.WriteLine();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace starcraft
{
internal class App
{
//생성자
public App()
{
int[,] map =
{
{1,1,1 },
{1,1,2 }
};
for(int i = 0; i < map.GetLength(0); i++)
{
for(int j =0;j<map.GetLength(1); j++)
{
int element = map[i, j];
Console.Write("[{0},{1}] : ({2})\t", i, j, element);
}
Console.WriteLine();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace starcraft
{
internal class App
{
//생성자
public App()
{
string [,] map =
{
{"풀","풀","풀" },
{"풀","풀","사막" }
};
for(int i = 0; i < map.GetLength(0); i++)
{
for(int j =0;j<map.GetLength(1); j++)
{
string element = map[i, j];
Console.Write("[{0},{1}] : ({2})\t", i, j, element);
}
Console.WriteLine();
}
}
}
}
'KDT > C# 프로그래밍' 카테고리의 다른 글
23/07/26 가짜 인벤토리 만들기1 (0) | 2023.07.26 |
---|---|
23/07/25 배열 복습 및 연습(집에서) (0) | 2023.07.25 |
23/07/25 다차원 배열2 (0) | 2023.07.25 |
23/07/25 다차원배열 (0) | 2023.07.25 |
23/07/25 인벤토리 (아이템 찾고 빼기) 복습 (0) | 2023.07.25 |