1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReadOnlyClass
{
    class ReadOnlyClass
    {
        public int x;
        public readonly int y = 1;
        public readonly int z;

        public ReadOnlyClass()
        {
            z = 24;
        }

        public ReadOnlyClass(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            ReadOnlyClass o1 = new ReadOnlyClass(1, 2, 3);
            Console.WriteLine("o1: x={0}, y={1}, z={2}", o1.x, o1.y, o1.z);

            ReadOnlyClass o2 = new ReadOnlyClass();
            Console.WriteLine("o2: x={0}, y={1}, z={2}", o2.x, o2.y, o2.z);

            o2.x = 5;
            o2.y = 6;
            o2.z = 7;
        }
    }
}


39~40번 라인에 문제가 있다고 컴파일 하지 않아도 친절하게 알려준다. 기특 기특. ^^


Posted by +깡통+