C# 2.0 New Feature(1)
今天下载并安装了visual stdio 2005 for team for develop for ..............^_^
赶快装一下,不错
我要传整屏,有限制,只能翻过来传上
再装msdn,
后发现sql server 2005 expess 太弱了,下了一个 正式版 for developer
1. new feature
有了一个很贴心 的特性
自定义可以被 foreach 的类
引用一下msdn的源程序了
1
//继承System.Collections.IEnumerable
2
public class dayWeeks : System.Collections.IEnumerable
3
{
4
//定义一个string[]
5
string[] dayWeek = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };
6
//重载GetEnumerator()
7
public System.Collections.IEnumerator GetEnumerator()
8
{
9
for (int i = 0; i < dayWeek.Length; i++)
10
{
11
//yield return 呵呵,^_^,专用于 iterator block
12
yield return dayWeek[i];
13
}
14
}
15
}
16
static void Main(string[] args)
17
{
18
new Program().printer("this is my vs 2005");
19
20
21
// Declare a list of type int
22
GenericList<int> list1 = new GenericList<int>();
23
24
// Declare a list of type string
25
GenericList<string> list2 = new GenericList<string>();
26
27
// Declare a list of type ExampleClass
28
GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
29
30
31
//好了定义一个对象
32
dayWeeks dayWeeks = new dayWeeks();
33
//go ahead foreach



.
34
foreach (string j in dayWeeks)
35
{
36
System.Console.WriteLine(j);
37
}
38
39
40
}
//继承System.Collections.IEnumerable2
public class dayWeeks : System.Collections.IEnumerable3
{4
//定义一个string[]5
string[] dayWeek = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };6
//重载GetEnumerator()7
public System.Collections.IEnumerator GetEnumerator()8
{9
for (int i = 0; i < dayWeek.Length; i++)10
{11
//yield return 呵呵,^_^,专用于 iterator block 12
yield return dayWeek[i];13
}14
}15
}16
static void Main(string[] args)17
{18
new Program().printer("this is my vs 2005");19

20

21
// Declare a list of type int22
GenericList<int> list1 = new GenericList<int>();23

24
// Declare a list of type string25
GenericList<string> list2 = new GenericList<string>();26

27
// Declare a list of type ExampleClass28
GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();29
30

31
//好了定义一个对象32
dayWeeks dayWeeks = new dayWeeks();33
//go ahead foreach



.34
foreach (string j in dayWeeks)35
{36
System.Console.WriteLine(j);37
}38

39
40
}

浙公网安备 33010602011771号