zoukankan
html css js c++ java
Hashtable 在程序中控制重复项
在一个索引器类中集合类中,为控制add方法,中不加入重复项
(ID)。
使用了Hashtable。
private Hashtable iDHash=new Hashtable();
/***添加item***/
#region
/***添加item***/
/**/
///
<summary>
///
添加item类
///
</summary>
///
<param name="newItem">
新Item类
</param>
public
void
Add(Item newItem)
{
int
id
=
newItem.B.ID;
//
(B为newItem 的一个属性类)
if
(
this
.iDHash.Contains(id))
{
return
;
}
else
{
this
.iDHash.Add(id,
""
);
List.Add(newItem);
}
}
#endregion
/***移除Item***/
#region
/***移除Item***/
/**/
///
<summary>
///
移除Item类
///
</summary>
///
<param name="oldItem">
待移除的Item类
</param>
public
void
Remove(Item oldItem)
//
移除类对象重载函数
{
if
(oldItem
!=
null
)
{
int
id
=
oldItem.B.ID;
this
.iDHash.Remove(id);
List.Remove(oldItem);
}
}
#endregion
/***移除Item***/
#region
/***移除Item***/
//
//
/ <summary>
//
//
/ 移除Item类
//
//
/ </summary>
//
//
/ <param name="index">待移除的index</param>
public
void
Remove(
int
index)
//
移除类对象重载函数
{
//
如果Item不存在,显示提示 messagebox
if
(index
>
Count
-
1
||
index
<
0
)
{
return
;
}
else
{
Item oldItem
=
(Item)
this
[index];
int
id
=
oldItem.B.ID;
this
.iDHash.Remove(id);
List.RemoveAt(index);
}
}
#endregion
查看全文
相关阅读:
不同压测场景的区别
常用的re模块的正则匹配的表达式
了解爬虫
robots.txt 协议
vue前台配置
短信验证码的使用
创建表
数据库配置
后台:Django项目创建
虚拟环境的搭建
原文地址:https://www.cnblogs.com/flashicp/p/714953.html
最新文章
2K Tallest Cow——差分
2N——数论+快速幂
2M——二分图+二分答案
UVA11383 Golden Tiger Claw——KM算法
[ARC066B] Xor Sum —— 递归
The Shortest Statement
Mister B and PR Shifts——思维题
最大的位或 ——位运算
2H [SCOI2016]萌萌哒-——倍增维护并查集
2G 连续攻击游戏
热门文章
2F Roads and Planes——缩点+dij
post请求四种传送正文的方式
发送post请求的接口
状态码对照表
发送get请求接口
接口测试用例和接口测试模板
工作中常用到的接口测试工具
怎么设计接口测试用例?
为什么要做接口测试?
接口测试的基础概念
Copyright © 2011-2022 走看看