-2
如何在Python C#索引,這樣[INT I] {獲取設置}實現?換句話說,如何用Python語言編寫的代碼如下?確實Python有一個方法來實現類似C#索引?
public class foo{
...
List<foo2> objfoo;
...
public foo2 this[int i] {
get{ return objfoo[i]; }}
}//end class foo
//in another class or method...
ofoo = new foo();
...
foo2 X = ofoo[3];
示例:http://code.activestate.com/recipes/577703-item-properties/ –