想为一个类定义[][]方法

定义item:
 public class TestItem
    {
        TestLine testLine = null;
        public TestLine this[int line]
        {
            get
            {
                if (testLine == null)
                {
                    testLine = new TestLine();
                }
                return testLine;
            }
        }
    }
定义line
public class TestLine
    {
        string strTest = "";
        public string this[int i]
        {
            get
            {
                strTest = "值为:" + i;
                return strTest;
            }
            set
            {
                strTest = "值为:" + i;
            }
        }
    }
使用[][]
:
TestItem item = new TestItem();
            MessageBox.Show(item[4][5]);
posted @ 2010-07-20 13:36  9421  阅读(197)  评论(0编辑  收藏  举报