zoukankan
html css js c++ java
IEnumerable
IEnumerator
Code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Linq;
4
using
System.Text;
5
using
System.Collections;
6
7
namespace
ConsoleApplication2
8
{
9
public
class
ListBoxList : IEnumerable
<
string
>
10
{
11
private
string
[] strings;
12
private
int
ctr
=
0
;
13
//
Enumerable class can return an enumerator
14
public
IEnumerator
<
string
>
GetEnumerator()
15
{
16
foreach
(
string
s
in
strings)
17
{
18
yield
return
s;
19
}
20
}
21
//
Explicit interface implemention
22
IEnumerator IEnumerable.GetEnumerator()
23
{
24
return
GetEnumerator();
25
}
26
//
initialize the listbox with string
27
public
ListBoxList(
params
string
[] initialString)
28
{
29
strings
=
new
String[
8
];
30
//
copy the strings passed into the constructor
31
foreach
(
string
s
in
initialString)
32
{
33
strings[ctr
++
]
=
s;
34
}
35
}
36
//
add a single string to the end of the listbox
37
public
void
Add(
string
theString)
38
{
39
strings[ctr]
=
theString;
40
ctr
++
;
41
}
42
//
allow array-like access
43
public
string
this
[
int
index]
44
{
45
46
get
47
{
48
if
(index
<
0
||
index
>=
strings.Length)
49
{
50
//
handle the index
51
}
return
strings[index];
52
}
53
set
54
{
55
strings[index]
=
value;
56
}
57
}
58
//
publish howmany strings you holds
59
public
int
GetEnmEntries()
60
{
61
return
ctr;
62
}
63
}
64
class
Program
65
{
66
static
void
Main(
string
[] args)
67
{
68
//
create a new listboxlist and initalize
69
ListBoxList lbt
=
new
ListBoxList(
"
hello
"
,
"
world
"
);
70
lbt.Add(
"
Who
"
);
71
lbt.Add(
"
Is
"
);
72
lbt.Add(
"
Douglas
"
);
73
lbt.Add(
"
Adams
"
);
74
string
subst
=
"
Universe
"
;
75
lbt[
1
]
=
subst;
76
//
accexx the listboxlist
77
foreach
(
string
s
in
lbt)
78
{
79
Console.WriteLine(s);
80
}
81
82
Console.ReadKey();
83
}
84
}
85
}
86
查看全文
相关阅读:
前端面试题及答案整理(一)
关于提高网站性能的几点建议(二)
关于提高网站性能的几点建议(一)
基于ArcGIS JS API的在线专题地图实现
关于婚姻的本质(转)
14亿人的战争:中国人用了30年望见计算力的珠峰(转载)
高效能人士的七个习惯--读书笔记
乔布斯在斯坦福大学的演讲
疫情加速医疗信息化行业景气上升,医疗信息化新黄金时代即将开启(转自公众号:先知研报)
oracleXEUniv最大连接数修改
原文地址:https://www.cnblogs.com/binlyzhuo/p/1433025.html
最新文章
WebForm 三级联动
WebForm 控件(一)、连接数据库
WebForm 基础
WinForm 进程、线程
js 给样式添加随机颜色
discuz 二次开发
说明文档编写
数字滚动效果
分页制作
textarea 换行操作
热门文章
文本框获取焦点时,光标出现在文本末尾
ZeroClipboard 插件实现文本复制到剪贴板
面向对象 —— 购物车
单行文本溢出和多行文本溢出显示省略号
Yii 简明学习教程
php简明学习教程
向ES6看齐,用更好的JavaScript(三)
向ES6看齐,用更好的JavaScript(二)
向ES6看齐,用更好的JavaScript(一)
前端面试题及答案整理(二)
Copyright © 2011-2022 走看看