0

オブジェクト階層 (Excel vba のようなもの) を作成する方法を学びたいです。私はいくつかのコードを書きましたが、これが正しい方法であるかどうかを尋ねたいと思います。また、このタイプのオブジェクト構造を作成すると、パフォーマンスに大きな影響があるかどうかも知りたいです。たとえば、次のようにオブジェクトにアクセスします。

Hotel hotel = new Hotel();

int x = hotel.Rooms[1].Count; // just an example

int y = hotel.Rooms.Room.Count; // just an example

    class Hotel
    {
        private int i;
        public Hotel()
        {
            i = 10; // some prossessing to give the value of i. Lets say 10
        }
        public _Rooms Rooms
        {
            get { return new _Rooms(i); }
        }
    }
    class _Rooms
    {
        private int _i;
        public _Rooms(int i)
        {
            this._i = i;
        }
        public _Room this[int i]
        {
            get { return new _Room(_i); }
        }

        public _Room Room // _Room Property
        {
            get { return new _Room(this._i); }
        }
    }
    class _Room
    {
        private int _i;
        public _Room(int i)
        {
            // some prossessing to give the value of i. Lets say :
            _i = i + 10;
        }
        public int Count
        {

            get { _i = 15; return _i; }
        }
    }

これは、私が達成したいモデルの簡単な例です。

4

0 に答える 0