using System;
using System.Collections;
namespace UploadItem
{
/// <summary>
/// UploadItems 的摘要说明。
/// </summary>
///
public class UploadItems:CollectionBase
{
#region/***索引器***/
/// <summary>
/// UploadItem索引器
/// </summary>
public UploadItem this [int index]
{
get
{
return (UploadItem)List[index];
}
set
{
if (value != null)
{
List[index] = value;
}
}
}//indexer
#endregion
#region/***添加UploadItem***/
/// <summary>
/// 添加UploadItem类
/// </summary>
/// <param name="newUploadItem">新UploadItem类</param>
public void Add(UploadItem newUploadItem)//添加类对象重载函数
{
List.Add(newUploadItem);
}
#endregion
#region/***移除UploadItem***/
/// <summary>
/// 移除UploadItem类
/// </summary>
/// <param name="oldUploadItem">待移除的UploadItem类</param>
public void Remove(UploadItem oldUploadItem)//移除类对象重载函数
{
List.Remove(oldUploadItem);
}
#endregion
}
}
下面这个是转贴的别人的,他们写的更加清晰,明了.很是佩服..
1.采用从CollectionBase抽象基类继承的方式实现Product集合类:
以数字做为索引值,详细成员查看msdn,还有更多的重载函数
using System;
using System.Collections;
public class productCollection:CollectionBase
{
public void Add(product newProduct)//添加类对象重载函数
{
List.Add(newProduct);
}
public void Remove(product oldProduct)//移除类对象重载函数
{
List.Remove(oldProduct);
}
public product this[int productIndex]//索引器重载函数
{
get
{
return (product)List[productIndex];
}
set
{
List[productIndex]=value;
}
}
}
2.采用从DictionaryBase抽象基类继承的方式实现Product集合类:
以字符串做为索引值,详细成员查看msdn,还有更多的重载函数
using System;
using System.Collections;
public class ShortStringDictionary : DictionaryBase
{
public String this[ String key ] //索引器重载函数
{
get
{
return( (String) Dictionary[key] );
}
set
{
Dictionary[key] = value;
}
}
public void Add( String key, String value ) //添加类对象重载函数
{
Dictionary.Add( key, value );
}
public void Remove( String key ) //移除类对象重载函数
{
Dictionary.Remove( key );
}
}