using system; using system.collections; public static void main(string [] args) { datarow mydatarow = new datarow(); dataitem mydataitem = new dataitem("text","value"); datarow.dataitems.add(mydataitem); console.writeline(mydatarow.dataitems[0].text); } public class datarow { public dataitemcollection dataitems; public datarow() { dataitems = new dataitemcollection(); } }
public class dataitem { private string _text; private string _value;
public dataitem(string text, string value) { _text=text; _value=value; }
public string text { get { return(_text); } set { _text=value; } }
public string value { get { return(_value); } set { _value=value; } }
}
public class dataitemcollection { private arraylist _array = new arraylist();
public virtual int count { get { return(_array.count); } }
public dataitem this[int index] //此處使用了indexer { get { if(index>=0 && index<_array.count) { return((dataitem)_array[index]); } else { throw new exception("index overflow"); } }
set { if(index>=0 && index<_array.count) { _array[index]=value; } else { throw new exception("index overflow"); } } }
public void add(dataitem item) { _array.add(item); }
public void remove(dataitem item) { _array.remove(item); }
public void removat(int i) { _array.removeat(i); } } 中國最大的web開發(fā)資源網(wǎng)站及技術(shù)社區(qū),