기본 방법
namespace MtUserIn;
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
Console.WriteLine(input);
}
}
예시
namespace MtUserIn;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Calculate());
}
public static int Calculate()
{
Console.WriteLine("Please enter the first number");
string number1Input = Console.ReadLine();
Console.WriteLine("Please enter the second number");
string number2Input = Console.ReadLine();
// 형변환 string -> int
int num1 = int.Parse(number1Input);
int num2 = int.Parse(number2Input);
int result = num1 + num2;
return result;
}
}
결과

'c# ☃️' 카테고리의 다른 글
[C#] 오퍼레이터 - 증가/감소/비교/연산자/AND/OR (0) | 2024.04.05 |
---|---|
[C#] 예외처리 - try/catch/finally (0) | 2024.03.25 |
[C#] 메소드 생성 방법 (0) | 2024.03.16 |
[c#] 전역변수 불변의 법칙 (0) | 2024.03.16 |
[c#] var 사용방법 (0) | 2024.03.04 |