C#

001_Input/Output

iwannabebackendexpert 2022. 3. 12. 02:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _001_IO
{
    internal class Program
    {
        static void Main(string[] args)
        {
            
            Console.Write("학번을 입력하세요 : ");
            string str_id = Console.ReadLine();
            int int_id = int.Parse(str_id);

            Console.Write("이름을 입력하세요 : ");
            string str_name = Console.ReadLine(); //int로 변환할 필요없음

            Console.WriteLine("[학번] : {0}",int_id);
            Console.WriteLine("[이름] : {0}",str_name);

        }
    }
}

출력 결과

- 문법이 c/c++에 비해 입출력조차 어려운것같다. 먼저 C#은 입력받는 모든 값은 문자열로 받는다. 그리고 Parse를 통해 int로 변환을 하게된다.  변수2 = int.Parse(변수1); 

단순 문법이 어려웠을뿐 로직상으로 어렵진않음.

- "WriteLine" 이면 "\n" 처럼 개행 . <-> "Write"면 개행이 되지않는다.

- 파이썬 처럼 출력시 {0}식으로 포메팅함.

'C#' 카테고리의 다른 글

004_BMI  (0) 2022.03.14
003_Relational(관계연산자)  (0) 2022.03.14
002_Arithmetic(사칙연산)  (0) 2022.03.14
C# - BMI 계산기  (0) 2022.03.12
C#? Framework? Library?  (0) 2022.03.03