포스트

(C#) 10. 코드의 흐름 제어 (function)

function

function

  • 최초 작성일: 2021년 3월 21일(월)

##

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;

namespace functionEX
{
    class Program
    {
        // 메소드 함수
        /*
            한정자 반환형식 이름(매개변수목록)
            {
            }
        */

        static void HelloWorld()
        {
            Console.WriteLine("Hello World");
        }

        // 덧셈 함수
        static int Add(int a, int b)
        {
            return a + b;
        }

        static void AddOne(ref int number)  // int값을 참조하는 것을 넘기겟다.
        {
            number = number + 1;
        }
        static void Main(string[] args)
        {
            Program.HelloWorld();
            // int result = Program.Add(4, 5);
            // int result = Add(4, 5);

            /////////////////////////////////////
            int a = 4;
            int b = 5;
            int result = Program.Add(b, a);
            Console.WriteLine(result);

            /////////////////////////////////////
            int c = 0;
            Program.AddOne(ref c);
            Console.WriteLine(c);
        }
    }
}

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.