유니티로 배우는 c#

프로퍼티

테오구 2021. 10. 10. 14:31
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Salary : MonoBehaviour
{

    private int salary;

    public int SalaryP{get{return salary;} private set{if(value < 0) salary = 10; else salary = value;}}//salary의 프러퍼티를 선언해줍니다.

    public int Bonus {get: set:}

    // Start is called before the first frame update
    void Start()
    {
        salary = 10; // 10의 값이 salary = value의 value로 
        // salary = value의 salary가 private int salary의 salary로 들어갑니다.
        Bonus = 10;
        print(Bonus);//property를 변수취급 할 수 있습니다.

    }

}
728x90

'유니티로 배우는 c#' 카테고리의 다른 글

인터페이스  (0) 2021.10.10
인덱서  (0) 2021.10.10
상속  (0) 2021.10.10
델리게이트  (0) 2021.10.10
구조체  (0) 2021.10.10