본문 바로가기
CSharp/CSharp 문법

프로퍼티 1

by MonoSoft 2025. 1. 30.
728x90
반응형

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
 
namespace Property
{    
 
    internal class Program
    {
        /*
        class BirthdayInfo
        {
            private string name;
            private DateTime birthday;
 
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
 
            public DateTime Birthday
            {
                get { return birthday; }
                set {  birthday = value; }
            }
 
            public int Age
            {
                get
                {
                    return new DateTime(DateTime.Now.Subtract(birthday).Ticks).Year;
                }
            }
        }       
        */
 
        /*
        class BirthdayInfo
        {
            public string Name { get; set; } = "Unknown";
            public DateTime Birthday { get; set; } = new DateTime(1, 1, 1);
            public int Age
            {
                get
                {
                    return new DateTime(DateTime.Now.Subtract(Birthday).Ticks).Year;
                }
            }
        }
        */
 
        /*
        class BirthdayInfo
        {
            public string Name
            {
                get; set;
            }
 
            public DateTime Birthday
            {
                get; set;
            }
 
            public int Age
            {
                get
                {
                    return new DateTime(DateTime.Now.Subtract(Birthday).Ticks).Year;
                }
            }
        }
        */
 
        static void Main(string[] args)
        {
 
 
            /*
            BirthdayInfo birth = new BirthdayInfo
            {
                Name = "서현",
                Birthday = new DateTime(1991, 6, 28)
            };
 
            Console.WriteLine($"Name : {birth.Name}");
            Console.WriteLine($"Birthday : {birth.Birthday.ToShortDateString()}");
            Console.WriteLine($"Age : {birth.Age}");
            /*
 
            /*
            BirthdayInfo birth = new BirthdayInfo();
            birth.Name = "홍길동";
            birth.Birthday = new DateTime(1991, 6, 26);
 
            Console.WriteLine($"Name : {birth.Name}");
            Console.WriteLine($"Birthday : {birth.Birthday.ToShortDateString()}");
            Console.WriteLine($"Age : {birth.Age}");
 
            birth.Name = "서현";
            birth.Birthday = new DateTime(1991, 6, 28);
 
            Console.WriteLine($"Name : {birth.Name}");
            Console.WriteLine($"Birthday : {birth.Birthday.ToShortDateString()}");
            Console.WriteLine($"Age : {birth.Age}");
            */
 
        }
    }
}

 

728x90
반응형

'CSharp > CSharp 문법' 카테고리의 다른 글

추상클래스  (0) 2024.12.12
클래스  (0) 2024.12.03
메소드 ( Method)  (0) 2024.08.16
코드의 흐림제어  (0) 2024.08.01
C# 문법  (0) 2024.07.01

댓글