C#/수업 내용

[C#] 논리 연산자

JSH1 2021. 8. 19. 11:31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            // 논리 연산자
            // AND : &&
            // A && B : A와 B모두 True면 결과 값은 True
            Console.Write("입력 1: ");
            string input1 = Console.ReadLine();
            Console.WriteLine("input1 : {0}", input1);

            // 형식 변환 string -> bool
            bool a = Convert.ToBoolean(input1);
            Console.WriteLine("A: {0}", a);


            Console.Write("입력 2: ");
            string input2 = Console.ReadLine();
            Console.WriteLine("input2 : {0}", input2);

            // 형식 변환 string -> bool
            bool b = Convert.ToBoolean(input2);
            Console.WriteLine("B: {0}", b);

            bool and = a && b;
            bool or = a || b;
            Console.WriteLine("A && B: {0}", and);
            Console.WriteLine("A || B: {0}", or);
            Console.WriteLine("(NOT)A && B: {0}", !and);
            Console.WriteLine("(NOT)A || B: {0}", !or);
        }
    }
}


 

'C# > 수업 내용' 카테고리의 다른 글

[C#] else if  (0) 2021.08.19
[C#] if  (0) 2021.08.19
[C#] 산술 연산자  (0) 2021.08.18
[C#] ConsoleKeyInfo, 키 입력  (0) 2021.08.18
2021-08-18 오전  (0) 2021.08.18