public static void Main(string[] args)
        {
            #region T에 대한 값 형식, 참조 형식 제약 조건

            StructArray <int> a = new StructArray <int>(3);
            a.Array[0] = 0;
            a.Array[1] = 1;
            a.Array[2] = 2;

            // StructArray<RefArray<int>> b = new StructArray<RefArray<int>>(3);

            RefArray <StructArray <int> > b = new RefArray <StructArray <int> >(3);
            b.Array[0] = new StructArray <int>(3);
            b.Array[1] = new StructArray <int>(6);
            b.Array[2] = new StructArray <int>(9);

            // RefArray<int> c = new RefArray<int>(3);
            #endregion

            BaseArray <Base> c = new BaseArray <Base>(3);
            c.Array[0] = new Base();
            c.Array[1] = new Derived();
            c.Array[2] = CreateInstance <Base>();

            BaseArray <Derived> d = new BaseArray <Derived>(2);
            d.Array[0] = new Derived();
            d.Array[1] = CreateInstance <Derived>();

            BaseArray <Derived> e = new BaseArray <Derived>(2);
            e.CopyArray <Derived>(d.Array);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            #region 값 형식, 참조 형식 제약조건
            StructArray <int> a = new StructArray <int>(3);  // T는 값 형식이어야 한다.
            a.Array[0] = 0;
            a.Array[1] = 1;
            a.Array[2] = 2;
            //StructArray<string> s = new StructArray<string>(3);  // error

            RefArray <StructArray <double> > b = new RefArray <StructArray <double> >(3);
            b.Array[0] = new StructArray <double>(5);
            b.Array[1] = new StructArray <double>(10);
            b.Array[2] = new StructArray <double>(15);
            //RefArray<int> i = new RefArray<int>(3);  // error
            #endregion

            BaseArray <Base> c = new BaseArray <Base>(3);
            c.Array[0] = new Base();
            c.Array[1] = new Derived();
            c.Array[2] = CreateInstance <Base>();

            BaseArray <Derived> d = new BaseArray <Derived>(2);
            d.Array[0] = new Derived();  // Base 형식은 여기에 할당 할 수 없다.
            d.Array[1] = CreateInstance <Derived>();

            BaseArray <Derived> e = new BaseArray <Derived>(2);
            e.CopyArray <Derived>(d.Array);
        }