shangxijie

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

C#通过提供索引器,可以象处理数组一样处理对象。特别是属性,每一个元素都以一个get或set方法暴露。

public class Skyscraper

{

Story[] stories;

public Story this [int index]

{

get

{

return stories [index];

}

set

{

if (value != null)

{

stories [index] = value;

}

}

}

//...

}

Skyscraper empireState = new Skyscraper (/*...*/);

empireState [102] = new Story ("The Top One", /*...*/);

posted on 2008-07-24 11:46  尚希杰  阅读(236)  评论(0编辑  收藏  举报