Menu



Manage

Study_C# > 11/Animal.cs Lines 37 | 851 바이트
다운로드

                        using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Weeks12
{
    internal class Animal
    {
        //자동 프로퍼티
        public int Age
        {
            get;
            set;
        }

        public void Eat()
        {
            Console.WriteLine("촵촵 먹습니다.");
        }


        //출력전용변수 out - 일종의 포인터 //TryParse가 이거 이용한거! 
        public bool NextAge(out int nextage) //out 쓰면 포인터처럼 동작함 but 반드시 값을 넣어야함 // C#두번째로 편리한 문법
        {
            if (Age <= 0) {
                nextage = Age;
                return false;
            }

            nextage = Age + 1;
            return true;
        }
    }
}