return anonymous type from method.

原文 http://tomasp.net/blog/cannot-return-anonymous-type-from-method.aspx
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[] { 1234567 }
19                        select new { N1 = i, N2 = i, N3 = i };
20             return list;
21         }



----------------------------------- http://www.cnblogs.com/rock_chen/
原文地址:https://www.cnblogs.com/rock_chen/p/1121082.html