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
查看全文
相关阅读:
js的深拷贝特别注意this的深拷贝
快速的熟悉一个angular的项目从run看起
关于angular路由中的#
AngularJS的Provider, Value, Constant, Service, Factory, Decorator的区别与详解
css页面缩放
jquery自定义window事件
js自定义事件
git分支
webpack知识小结--require.context方法
Vue 创建组件的两种方法
原文地址:https://www.cnblogs.com/binlyzhuo/p/1433025.html
最新文章
BZOJ 1060: [ZJOI2007]时态同步
LUOGU P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
bzoj 5072 [Lydsy1710月赛]小A的树——树形dp
bzoj 2151 种树——贪心+后悔
bzoj 1098 [POI2007]办公楼biu——链表
bzoj4197 [Noi2015]寿司晚宴——状压DP
bzoj3555 [Ctsc2014]企鹅QQ——字符串哈希
bzoj2595 [Wc2008]游览计划——斯坦纳树
洛谷P3808 & P3796 AC自动机模板
bzoj4977 跳伞求生——贪心
热门文章
bzoj4004 [JLOI2015]装备购买——线性基+贪心
P4135 作诗——分块
bzoj4260 REBXOR——Trie树
Couleur(启发式 + 主席树)(终于补坑了)
Pandaria(Kruskal重构树+线段树合并)
模拟退火算法初看
匈牙利算法实战codevs1022覆盖
匈牙利算法(模板)
$modalInstance
js字符串和数组的相互转化
Copyright © 2011-2022 走看看