300x250

    class productDTO
    {

        private string name;

 

        public string GetName()
        {
            return name;
        }
        public void SetName(string name)
        {
            this.name = name;
        }

    }


        private void button1_Click(object sender, EventArgs e)
        {
            productDTO productDTO = new productDTO();

            productDTO.SetName("컴퓨터");

            MessageBox.Show(productDTO.GetName());


        }
    

 

 

평소에난 get, set을 이렇게 사용 했는데 C# 에서는 좀더 편하게 사용이 가능했다.

 

    class productDTO 
    {

        private string name;

 

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

    }

 

        private void button1_Click(object sender, EventArgs e) 
        { 
            productDTO productDTO = new productDTO(); 

 

            productDTO.Name = "컴퓨터";
            MessageBox.Show(productDTO.Name);
        } 

 

 

 

300x250