Code Archive/C#

Step2. C# 배열 선언 방법 및 함수

쌍큐 2017. 3. 3. 18:32

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Step2

{

    class Program

    {   

        static void addArray(int[] arr, int num)

        {

            for(int i = 0; i < arr.Length; i++)

            {

                arr[i] += num;

            }

        }

        static void showArray(int[] arr)

        {

            for (int i = 0; i < arr.Length; i++)

            {

                Console.WriteLine(arr[i]);

            }

        }

        static int inputNumber()

        {

            return int.Parse(Console.ReadLine());

        }

        static void showMessage()

        {

            Console.WriteLine("매개변수 및 리턴이 없는 함수");

        }

        static int sumArray(int[] arr)

        {

            int total = 0;

            for (int i = 0; i < arr.Length; i++)

            {

                total += arr[i];

            }

            return total;

        }

        static void Main(string[] args)

        {

            int[] arr1= new int[10];

            int[] arr2 = new int[10]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

            int[] arr3 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

            showArray(arr1);

            showArray(arr2);

            showArray(arr3);

            addArray(arr2, 10);

            showArray(arr2);

        }

    }

}



'Code Archive > C#' 카테고리의 다른 글

Step3. Thread 기본 문법  (0) 2017.03.03
Step1. C# 기초문법  (0) 2017.03.03