经过一些研究和反复试验后,我想我找到了一个解决方案System.Collections.ArrayList
.但是,这不适用于通过索引获取值.要做到这一点,我创建了一个新的类ComArrayList
,从继承ArrayList
,并增加了新的方法GetByIndex
和SetByIndex
.
public class ComArrayList : System.Collections.ArrayList { public virtual object GetByIndex(int index) { return base[index]; } public virtual void SetByIndex(int index, object value) { base[index] = value; } }
public ComArrayList GetDepartments() { // return a list of Departments from the database }
The third department
<%= departments.GetByIndex(2).Name %>
由于您只是在ASP中使用数据,我建议您返回Department[]
.这应该直接映射到COM中的SAFEARRAY.它也支持枚举和索引访问.
public Department[] GetDepartments() { var departments = new List(); // populate list from database return departments.ToArray(); }