Notice
Recent Posts
Recent Comments
«   2024/09   »
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
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

16. C#의 연산자와 식 본문

초보자를 위한 C# 200제/C# 입문

16. C#의 연산자와 식

빌드이너프 2024. 9. 12. 20:32

연산자 종류

 

연산자는 중복되어 사용 가능

"3+4"에서 '+'는 산술연산자로 사용되어 계산의 결과는 7이지만,

"Hello " + "World!"와 같이 문자열과 문자열 사이에 있는 '+'는 문자열 연결 연산자로 사용되어 결과는 "Hello World!"가 된다.

 

코드

using System;

namespace A016_Operators
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(3 + 4 * 5);
            Console.WriteLine((3 + 4) * 5);
            Console.WriteLine(3 + 4 / 5);
            Console.WriteLine(4 / 5 * 3);

            int a = 10, b = 20, c;
            Console.WriteLine(c = a + b);
        }
    }
}

 

실행