using System; using System.Collections;namespace RaulRedondo.PatternRecognition.Common { /// <summary> /// ClusterCollection µÄժҪ˵Ã÷¡£ /// </summary> public class ClusterCollection : CollectionBase { public Cluster Add(Cluster value) { this.List.Add(value); return value; } public void AddRange(Cluster[] values) { foreach(Cluster p in values) this.List.Add(p); } public Cluster this[int index] { get { return this.List[index] as Cluster; } set { this.List[index] = value; } } public int IndexOf(Cluster value ) { return this.List.IndexOf(value); } public void Insert(int index, Cluster value) { this.List.Insert(index, value ); } public void Remove(Cluster value ) { this.List.Remove( value ); } public bool Contains(Cluster value ) { return this.List.Contains(value); } protected override void OnInsert(int index, Object value ) { if (value.GetType() != typeof(Cluster)) throw new ArgumentException("value must be of type Cluster.", "value"); } protected override void OnRemove(int index, Object value ) { if (value.GetType() != typeof(Cluster)) throw new ArgumentException("value must be of type Cluster.", "value"); } protected override void OnSet(int index, Object oldValue, Object newValue) { if (newValue.GetType() != typeof(Cluster)) throw new ArgumentException("newValue must be of type Cluster.", "newValue"); } protected override void OnValidate(Object value ) { if (value.GetType() != typeof(Cluster)) throw new ArgumentException("value must be of type Cluster."); } } } 你把类名查找替换就可以了
{
public string this[int index]
{
get
{
return (string)List[index];
}
}
}[====我的精英团队====] www.51team.com
派生后要重载一些属性和方法,具体的看MSDN,查CollectionBase就可以,里面有一个详细的例子。
using System.Collections;namespace RaulRedondo.PatternRecognition.Common
{
/// <summary>
/// ClusterCollection µÄժҪ˵Ã÷¡£
/// </summary>
public class ClusterCollection : CollectionBase
{
public Cluster Add(Cluster value)
{
this.List.Add(value);
return value;
} public void AddRange(Cluster[] values)
{
foreach(Cluster p in values)
this.List.Add(p);
} public Cluster this[int index]
{
get
{
return this.List[index] as Cluster;
}
set
{
this.List[index] = value;
}
} public int IndexOf(Cluster value )
{
return this.List.IndexOf(value);
} public void Insert(int index, Cluster value)
{
this.List.Insert(index, value );
} public void Remove(Cluster value )
{
this.List.Remove( value );
} public bool Contains(Cluster value )
{
return this.List.Contains(value);
} protected override void OnInsert(int index, Object value )
{
if (value.GetType() != typeof(Cluster))
throw new ArgumentException("value must be of type Cluster.", "value");
} protected override void OnRemove(int index, Object value )
{
if (value.GetType() != typeof(Cluster))
throw new ArgumentException("value must be of type Cluster.", "value");
} protected override void OnSet(int index, Object oldValue, Object newValue)
{
if (newValue.GetType() != typeof(Cluster))
throw new ArgumentException("newValue must be of type Cluster.", "newValue");
} protected override void OnValidate(Object value )
{
if (value.GetType() != typeof(Cluster))
throw new ArgumentException("value must be of type Cluster.");
}
}
}
你把类名查找替换就可以了