2019-10-17 19일차 get,set
Console Programming/C# Console 2019. 10. 17. 11:18Program.cs
namespace Syntax02
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
App.cs
using System;
namespace Syntax02
{
public class App
{
public App()
{
Date date = new Date();
int month = date.Month; //초기값을 get을 통해 가져옴
Console.WriteLine(month);
date.Month = 11; //date.month에 11이라는 값을 넣음
month = date.Month; //month에 date.month를 가져와 넣음
Console.WriteLine(month);
}
}
}
Date.cs
namespace Syntax02
{
public class Date
{
private int month = 7; //초기값이 7
public int Month
{
get
{
return this.month;
}
set
{
if ((value > 0) && (value < 13))
{
this.month = value;
}
}
}
}
}

'Console Programming > C# Console' 카테고리의 다른 글
| 2019-10-17 19일차 클래스의 상속 (0) | 2019.10.17 |
|---|---|
| 2019-10-17 19일차 get,set 몬스터와 몬스터데이터 get,set으로 만들고 접근하기 (0) | 2019.10.17 |
| 2019-10-16 Json에 데이터 추가하기 쿠키런캐릭터 (0) | 2019.10.16 |
| 2019-10-16 Dictionary 컬렉션에 데이터추가하기 (json으로) (2) 쿠키런캐릭터 (0) | 2019.10.16 |
| 2019-10-16 Dictionary 컬렉션에 데이터추가하기 (json으로) (2) 쿠키런캐릭터 (0) | 2019.10.16 |

