0318 다차원 배열 (맵 변경하기)

2021. 3. 18. 16:51C#/수업내용

public App()
        {
            Console.WriteLine("App");
            int[,] arr = {
                { 101,101,101,101 },
                { 100,100,100,101 },
                { 100,100,100,100 },
            };

            for (int i = 0; i < arr.GetLength(0); i++) 
            {
                for (int j = 0; j < arr.GetLength(1); j++) 
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }

            Console.WriteLine("===========숫자 변경===========");
            arr[0, 3] = 300;

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
        }


public App()
        {
            Console.WriteLine("App");
            int[,] arr = {
                { 300,301 },
                { 100,302 },
                { 100,100 },
                { 101,101 }
            };

            for (int i = 0; i < arr.GetLength(0); i++) 
            {
                for (int j = 0; j < arr.GetLength(1); j++) 
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }

            Console.WriteLine("===========숫자 변경===========");
            arr[0, 0] = 100;

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
        }


 

public App()
        {
            Console.WriteLine("App");
            int[,] arr = {
                { 100,100,101 },
                { 100,100,100 },
                { 100,100,100 }
            };

            for (int i = 0; i < arr.GetLength(0); i++) 
            {
                for (int j = 0; j < arr.GetLength(1); j++) 
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine("===========숫자 변경===========");
            arr[0, 0] = 300;
            arr[0, 1] = 301;
            arr[0, 2] = 302;
            arr[1, 1] = 303;
            arr[1, 2] = 304;
            arr[2, 2] = 303;

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
        }


 

public App()
        {
            Console.WriteLine("App");
            int[,] arr = {
                { 300,302,303,304,100 },
                { 100,301,307,306,305 },
                { 100,100,301,308,100 }
            };

            for(int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++) 
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine("===========숫자 변경===========");
            arr[0, 0] = 100;
            arr[0, 1] = 100;
            arr[0, 2] = 101;
            arr[0, 3] = 101;
            arr[0, 4] = 101;
            arr[1, 1] = 100;
            arr[1, 2] = 100;
            arr[1, 3] = 308;
            arr[1, 4] = 304;
            arr[2, 2] = 310;
            arr[2, 3] = 309;
            arr[2, 4] = 308;
            
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("{0,2} ", arr[i, j]);
                }
                Console.WriteLine();
            }
        }