Form1.cs[디자인]
-Customer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace Customer
{
class Customer
{
public string LastName;
public string FirstName;
//private int _Age;
private bool _IsQualified; // 이 값이 true면 입양가능, false면 입양불가능 (기준: 18세) : 접근 불가능하게 만들어야함
private DateTime _Birthday;
public string Address;
public string Description;
public Customer(string firstname, string lastname, DateTime birthday)
{
this.FirstName = firstname;
this.LastName = lastname;
//this._Age = age;
this._Birthday = birthday;
this._IsQualified = Age >= 18;
}
// age를 읽을 수 있는 메서드를 생성하자
/*public int GetAge()
{
return _Age;
}
// 나이 값을 넣는 메서드
public void SetAge(int age)
{
_Age = age;
_IsQualified = age >= 18;
}*/
/// <summary>
/// Age의 프로퍼티 설정
/// </summary>
public int Age
{
get { return DateTime.Now.Year - Birthday.Year; }
/*set
{
// value는 int형으로 들어온 매개변수다.
_Age = value;
_IsQualified = value >= 18;
}*/
}
// IsQualified를 읽을 수 있는 메서드를 생성하자
/*public bool GetIsQualifeid()
{
return _IsQualified;
}*/
/// <summary>
/// IsQualified의 프로퍼티 설정
/// </summary>
public bool IsQualified
{
// get은 read, set은 write
get
{
return _IsQualified;
}
}
/*public string Fullname()
{
return FirstName + LastName;
}*/
/// <summary>
/// Fullname의 프로퍼티 설정
/// </summary>
public string FullName
{
get
{
return LastName + FirstName ;
}
}
public DateTime Birthday
{
get
{
return _Birthday;
}
set
{
_Birthday = value;
_IsQualified = Age >= 18;
}
}
}
}
- Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Customer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CreateCustomer_Click(object sender, EventArgs e)
{
DateTime birthday = new DateTime(2005, 05, 12);
Customer cus = new Customer("범이", "장", birthday);
cus.Address = "김해시 내외동 금관대로 1277번길";
cus.Description = "범이는 귀엽다";
CusFullName.Text = cus.FullName;
CusAge.Text = cus.Age.ToString();
CusAddress.Text = cus.Address;
CusDescription.Text = cus.Description;
CusQualified.Text = cus.IsQualified.ToString();
}
}
}
'C#' 카테고리의 다른 글
2020.09.09 - C# Visualization (0) | 2020.09.09 |
---|---|
2020.09.08 - 암호화(C#) (0) | 2020.09.08 |
2020.09.01 - C#의 구조체 (0) | 2020.09.01 |
2020.09.01 - C# 클래스 선언, 생성자, 접근제한자 (0) | 2020.09.01 |
2020.08.27(목) - C# (0) | 2020.08.27 |