C#,如何创建类的集合类

[复制链接]
查看11 | 回复3 | 2008-11-28 11:23:45 | 显示全部楼层 |阅读模式
C#代码,这样:
publicclass User

{
............

}
publicclass UserCollection

{
............这里如何写?

}
声明时:
UserCollectionuc=new UserCollection();
User u=uc[1];
请问大家如何写这样的程序!!!急啊!!!就是一个对象的集合类如何写?
lcg1986 的回答虽然不准确多少,有些错误,ArrayList.Length 应为:ArrayList.Count,还有
get
{
if(index-1)
{
return userArray[index];
}
}
错在:并不是所有路径都返回值!
不过还是很谢谢你,思路是对了,正是我想要的!已解决!呵呵!

回复

使用道具 举报

千问 | 2008-11-28 11:23:45 | 显示全部楼层
你用的是不是Visual Studio 2005,如果是的话,那么你可以直接使用.NET 2.0提供的泛型集合。具体使用如下:引用System.Collections.Generic命名空间,然后使用如下代码:List[U] userList=new List[U]();User user=new User();userList.Add(user);这样就可以创建一个只能存储User类对象的集合类了。...
回复

使用道具 举报

千问 | 2008-11-28 11:23:45 | 显示全部楼层
publicclassUserCollection{ArrayListuserArray=newArrayList();publicUserthis[intindex]{get{if(index-1){returnuserAr...
回复

使用道具 举报

千问 | 2008-11-28 11:23:45 | 显示全部楼层
public class UserCollection { ArrayList userArray = new ArrayList();public User this[int index]{
get
{
if(index-1)
...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行