본문 바로가기

.NET/C# Basic

프로퍼티 관련소스

반응형
using System;
using System.Collections.Generic;
using System.Text;

namespace pt1
{
    class Point1
    {
        public int a;
        public int b;

        public Point1(int a,int b)
        {
            this.a = a;
            this.b = b;
        }
    }

    class Point2
    {
        private int aa;
        private int bb;

        public void set(int aa,int bb)
        {
            this.aa = aa;
            this.bb = bb;
        }
        public int getaa()
        {
            return aa;
        }
        public int getbb()
        {
            return bb;
        }
    }
    class Point3
    {
        private int xx;
        private int yy;

        public int Xx
        {
            get { return xx; }
            set { xx = value; }
        }
        public int Yy
        {
            get { return yy; }
            set { yy = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Point1 pt1 = new Point1(1,2);
            Console.WriteLine("x={0} y={1}",pt1.a,pt1.b);
            //Console.ReadKey();

            Point2 pt2 = new Point2();
            pt2.set(10, 20);
            Console.WriteLine("{0},{1}", pt2.getaa() , pt2.getbb());

            Point3 pt3 = new Point3();
            pt3.Xx=50;
            pt3.Yy=60;
            Console.WriteLine("{0},{1}",pt3.Xx,pt3.Yy);
        }
    }

'.NET > C# Basic' 카테고리의 다른 글

C# PPT 5  (0) 2008.10.02
C# PPT 4  (0) 2008.10.02
C# PPT 3  (0) 2008.10.02
C# PPT 2  (2) 2008.10.02
프로퍼티 설명 get/set  (0) 2008.10.01
프로퍼티 예제  (0) 2008.10.01
프로퍼티  (0) 2008.10.01
인스턴스  (0) 2008.10.01