본문 바로가기

c#

C# [10] 데이터 저장을 위한 배열 클래스의 개념& 배열 초기화, 값 저장, 길이 출력 실습 & foreach 문을 통한 배열의 값 출력하기 실습

728x90
반응형
using System;

class Program
{
    public static void Main(string[] args)
    {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;

        int[] array2 = new int[] { 1, 2, 3 };

        int[] array3 = { 4, 5, 6 };

        Console.WriteLine(array1.Length);

        for (int i = 0; i < array3.Length; i++)
        {
            Console.WriteLine(array3[i]);
        }

        foreach (int item in array3)
        {
            Console.WriteLine(item);
        }
    }
}
728x90
반응형