/// <summary> /// 根据索引位置插入一个列表项 /// </summary> /// <param name="index">索引位置</param> /// <param name="item">要插入的列表项</param> public void Insert(int index, ChatListItem item) { if (index < 0 || index >= this.count) { throw new IndexOutOfRangeException("Index was outside the bounds of the array"); } if (item == null) { throw new ArgumentNullException("Item cannot be null"); } this.EnsureSpace(1); for (int i = this.count; i > index; i--) { m_arrItem[i] = m_arrItem[i - 1]; } item.OwnerChatListBox = this.owner; m_arrItem[index] = item; this.count++; this.owner.Invalidate(); }
/// <summary> /// 判断一个列表项是否在集合内 /// </summary> /// <param name="item">要判断的列表项</param> /// <returns>是否在列表项</returns> public bool Contains(ChatListItem item) { return(this.IndexOf(item) != -1); }
/// <summary> /// 获取列表项所在的索引位置 /// </summary> /// <param name="item">要获取的列表项</param> /// <returns>索引位置</returns> public int IndexOf(ChatListItem item) { return(Array.IndexOf <ChatListItem>(m_arrItem, item)); }