C#/C#언어

0318 _ 다차원 배열 _ 맵 바꾸기 예제

minquu 2021. 3. 18. 17:39
반응형

1.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {101, 101, 101, 101 },
                {100, 100, 100, 101 },
                {100, 100, 100, 100 }
            };
            Console.WriteLine("**************************");
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }
            Console.WriteLine("**************************");
            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}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }
            Console.WriteLine("**************************");
        }
    }
}

 

------

2.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {300, 310 },
                {100, 302 },
                {100, 100 },
                {101, 101 },
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("******************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", 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}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }
            Console.WriteLine("******************************");
        }
    }
}

 

 

 

-----

 

3.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            int[,] arr = {
                {100, 100, 101 },
                {100, 100, 100 },
                {100, 100, 100 }
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));

            Console.WriteLine("******************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                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;
            Console.WriteLine("******************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine("");
            }
        }

    }
}

----

 

4.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            int[,] arr = {
                {300, 302, 303, 304, 100 },
                {100, 301, 307, 306, 305 },
                {100, 100, 301, 308, 100 }
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("******************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}",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}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }

        }
    }
}

반응형

'C# > C#언어' 카테고리의 다른 글

0322 _ delegates 연습예제  (0) 2021.03.22
0318_ 다차원 _ 2차원 배열 isometric view  (0) 2021.03.18
0318 _ 다차원 연습 문제 1 _ 10개  (0) 2021.03.18
0317 _ abstract 연습 예제  (0) 2021.03.17
0317_ interface 연습  (0) 2021.03.17