1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
testCombox
{
public
partial
class
Form1 : Form
{
test t1 =
new
test(
"t1"
, 1);
test t2 =
new
test(
"t2"
, 2);
test t3 =
new
test(
"t3"
, 3);
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
}
private
void
btnAdd_Click(
object
sender, EventArgs e)
{
this
.listBox1.Items.Add(t1);
this
.listBox1.Items.Add(t2);
this
.listBox1.Items.Add(t3);
}
/// <summary>
/// 判断根据Object是否能够删除t2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnDel_Click(
object
sender, EventArgs e)
{
this
.listBox1.Items.Remove(t2);
//删除成功,下面测试listBox1.Items.Remove
//方法是利用ToString还是利用gethashCode来定位元素的
}
/// <summary>
/// 判断listBox1.Items.Remove(object)是不是根据Object的Tostring方法来删除元素的
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
button1_Click(
object
sender, EventArgs e)
{
t2.Name =
"t22"
;
//修改元素的名称,看是否能够被删除。
this
.listBox1.Items.Remove(t2);
//删除成功,证明Remove方法可能是根据getHashCode来删除元素的
}
}
/// <summary>
/// 一个测试类
/// </summary>
public
class
test
{
public
string
Name {
get
;
set
; }
public
override
string
ToString()
{
return
this
.Name;
}
public
int
testInt = 0;
public
test(
string
name,
int
num)
{
this
.Name = name;
testInt = num;
}
}
}
|
作者:kissazi2
出处:http://www.cnblogs.com/kissazi2/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
转载:http://www.cnblogs.com/kissazi2/archive/2013/01/01/2841382.html