如下类,我不能理解那个this.count, 我没有看到count的定义,请大神帮忙解释一下,非常感谢.
public class FieldParameters : System.Collections.CollectionBase
{
/// <summary>
/// 增加参数
/// </summary>
/// <param name="item"></param>
public void Add(FieldItem item)
{
if (Find(item.Name) > -1)
{
throw new ArgumentException("The field name has existed!");
}
List.Add(item);
} public int Find(string fieldName)
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].Name == fieldName)
return i;
}
return -1;
}
public class FieldParameters : System.Collections.CollectionBase
{
/// <summary>
/// 增加参数
/// </summary>
/// <param name="item"></param>
public void Add(FieldItem item)
{
if (Find(item.Name) > -1)
{
throw new ArgumentException("The field name has existed!");
}
List.Add(item);
} public int Find(string fieldName)
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].Name == fieldName)
return i;
}
return -1;
}
解决方案 »
- 如何实现截图,并对截图进行涂污
- c#开发的桌面应用程序,程序是个循环处理,在运行时,有是窗口激活不了
- 让flowLayoutPanel分页显示的问题
- 小问题 100求救 如何让数据库中的数据 显示在PictureBoX上?大家帮忙啊 急啊
- 关于Exception中获取出错函数以及参数的问题
- 如何定义常量数组?
- 如何在我的程序启动时候关闭内存内所有其他程序?
- 怎么样在一个public class 类里对一个动态生成的listview控件进行操作?
- 请问在图片控件上增删标志图应该怎么实现?
- 我的msdn可能出问题了
- 如何从字符串中提取指定的字符?如何从字符串中提取指定的字符?
- 用C#代码写一个数据库导入系统,只是将excel表导入到SQL2008数据库中
继承了
你不是继承了 System.Collections.CollectionBase吗?这里的this.count就表示当前实例中的元素的数量.
// 为强类型集合提供 abstract 基类。
[Serializable]
[ComVisible(true)]
public abstract class CollectionBase : IList, ICollection, IEnumerable
{
// 摘要:
// 使用默认初始容量初始化 System.Collections.CollectionBase 类的新实例。
protected CollectionBase();
//
// 摘要:
// 使用指定的容量初始化 System.Collections.CollectionBase 类的新实例。
//
// 参数:
// capacity:
// 新列表最初可以存储的元素数。
protected CollectionBase(int capacity); // 摘要:
// 获取或设置 System.Collections.CollectionBase 可包含的元素数。
//
// 返回结果:
// System.Collections.CollectionBase 可包含的元素数。
//
// 异常:
// System.ArgumentOutOfRangeException:
// System.Collections.CollectionBase.Capacity 设置为小于 System.Collections.CollectionBase.Count
// 的值。
//
// System.OutOfMemoryException:
// 系统中没有足够的可用内存。
[ComVisible(false)]
public int Capacity { get; set; }
//
// 摘要:
// 获取包含在 System.Collections.CollectionBase 实例中的元素数。不能重写此属性。
//
// 返回结果:
// 包含在 System.Collections.CollectionBase 实例中的元素数。检索此属性的值的运算复杂度为 O(1)。
public int Count { get; } //你要找的Count
//
// 摘要:
// 获取一个 System.Collections.ArrayList,它包含 System.Collections.CollectionBase 实例中元素的列表。
//
// 返回结果:
// 表示 System.Collections.CollectionBase 实例本身的 System.Collections.ArrayList。检索此属性的值的运算复杂度为
// O(1)。
protected ArrayList InnerList { get; }
//
// 摘要:
// 获取一个 System.Collections.IList,它包含 System.Collections.CollectionBase 实例中元素的列表。
//
// 返回结果:
// 表示 System.Collections.CollectionBase 实例本身的 System.Collections.IList。
protected IList List { get; } // 摘要:
// 从 System.Collections.CollectionBase 实例移除所有对象。不能重写此方法。
public void Clear();
//
// 摘要:
// 返回循环访问 System.Collections.CollectionBase 实例的枚举器。
//
// 返回结果:
// 用于 System.Collections.CollectionBase 实例的 System.Collections.IEnumerator。
public IEnumerator GetEnumerator();
//
// 摘要:
// 当清除 System.Collections.CollectionBase 实例的内容时执行其他自定义进程。
protected virtual void OnClear();
//
// 摘要:
// 在清除 System.Collections.CollectionBase 实例的内容之后执行其他自定义进程。
protected virtual void OnClearComplete();
//
// 摘要:
// 在向 System.Collections.CollectionBase 实例中插入新元素之前执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,在该处插入 value。
//
// value:
// index 处的元素的新值。
protected virtual void OnInsert(int index, object value);
//
// 摘要:
// 在向 System.Collections.CollectionBase 实例中插入新元素之后执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,在该处插入 value。
//
// value:
// index 处的元素的新值。
protected virtual void OnInsertComplete(int index, object value);
//
// 摘要:
// 当从 System.Collections.CollectionBase 实例移除元素时执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,可在该位置找到 value。
//
// value:
// 要从 index 移除的元素的值。
protected virtual void OnRemove(int index, object value);
//
// 摘要:
// 在从 System.Collections.CollectionBase 实例中移除元素之后执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,可在该位置找到 value。
//
// value:
// 要从 index 移除的元素的值。
protected virtual void OnRemoveComplete(int index, object value);
//
// 摘要:
// 当在 System.Collections.CollectionBase 实例中设置值之前执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,可在该位置找到 oldValue。
//
// oldValue:
// 要用 newValue 替换的值。
//
// newValue:
// index 处的元素的新值。
protected virtual void OnSet(int index, object oldValue, object newValue);
//
// 摘要:
// 当在 System.Collections.CollectionBase 实例中设置值后执行其他自定义进程。
//
// 参数:
// index:
// 从零开始的索引,可在该位置找到 oldValue。
//
// oldValue:
// 要用 newValue 替换的值。
//
// newValue:
// index 处的元素的新值。
protected virtual void OnSetComplete(int index, object oldValue, object newValue);
//
// 摘要:
// 当验证值时执行其他自定义进程。
//
// 参数:
// value:
// 要验证的对象。
//
// 异常:
// System.ArgumentNullException:
// value 为 null。
protected virtual void OnValidate(object value);
//
// 摘要:
// 移除 System.Collections.CollectionBase 实例的指定索引处的元素。此方法不可重写。
//
// 参数:
// index:
// 要移除的元素的从零开始的索引。
//
// 异常:
// System.ArgumentOutOfRangeException:
// index 小于零。- 或 -index 等于或大于 System.Collections.CollectionBase.Count。
public void RemoveAt(int index);
}