TESTCODE:
1 private void button1_Click(object sender, EventArgs e)
2 {
3 IEnumerable list = GetAA();
4 foreach (var v in list)
5 {
6 var t = Cast(v,new {N1=0,N2=0,N3=0});
7 MessageBox.Show(t.N1.ToString());
8 }
9 }
10
11 T Cast<T>(object obj, T type)
12 {
13 return (T)obj;
14 }
15
16 public IEnumerable GetAA()
17 {
18 var list = from i in new int[] { 1, 2, 3, 4, 5, 6, 7 }
19 select new { N1 = i, N2 = i, N3 = i };
20 return list;
21 }
2 {
3 IEnumerable list = GetAA();
4 foreach (var v in list)
5 {
6 var t = Cast(v,new {N1=0,N2=0,N3=0});
7 MessageBox.Show(t.N1.ToString());
8 }
9 }
10
11 T Cast<T>(object obj, T type)
12 {
13 return (T)obj;
14 }
15
16 public IEnumerable GetAA()
17 {
18 var list = from i in new int[] { 1, 2, 3, 4, 5, 6, 7 }
19 select new { N1 = i, N2 = i, N3 = i };
20 return list;
21 }