C#프로그래밍
1차원 배열
다모아
2023. 7. 25. 14:46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Game2048
{
public class App
{
//생성자
public App()
{
//배열의 인스턴스화
int[] arr = new int[3]; // 3 : length
int[] arr2 = { 1, 2, 3 }; // 3
//인덱스로 배열의 요소에 접근
arr[0] = 1;
Console.WriteLine(arr[0]);
//배열의 순회 (요소를 출력)
for(int i = 0; i < arr.Length; i++)
{
int num = arr[i];
Console.WriteLine(arr[i]);
}
foreach(int num in arr)
{
Console.WriteLine(num);
}
}
}
}