Notice
Recent Posts
Recent Comments
Link
스토리지
[3.10] 메소드 연습 1 - 방향판별 본문
using System;
namespace Study00
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Move("서"));
Console.WriteLine(Move("동"));
Console.WriteLine(Move("동"));
Console.WriteLine(Move("북"));
Console.WriteLine(Move("이상한주소"));
}
//반환값이 있는 메소드
static private string Move(string direction)
{
if (direction != "동" && direction != "서" && direction != "남" && direction != "북")
return "그 위치로 이동할 수 없습니다";
return direction + "쪽으로 이동하였습니다.";
}
//반환값이 없는 메소드
static private override void Move(string direction)
{
if (direction != "동" && direction != "서" && direction != "남" && direction != "북")
Console.WriteLine("그 위치로 이동할 수 없습니다");
else
Console.WriteLine(direction + "쪽으로 이동하였습니다.");
}
}
}
'Unity > 수업내용(C#)' 카테고리의 다른 글
[3.11] Class 생성 및 객체 생성 (0) | 2021.03.11 |
---|---|
[3.10] 메소드 연습 2 - 반환값만 있는 메소드 (0) | 2021.03.10 |
[3.10] 메소드 Method (0) | 2021.03.10 |
[3.10] 콘솔창 색 바꾸기 (번외) (0) | 2021.03.10 |
[3.10] 구구단 출력 (0) | 2021.03.10 |
Comments