If the data source does not implement the ienumerable <t> interface and only implements the ienumerable interface, you must specify a type for the range variable (that is, the range variable must let the compiler know what the type is)
Data source: glist
Range variable: G
Code:
- Public class guestinfo
- {
- Public string name {Get; set ;}
- Public int age {Get; set ;}
- Public String Tel {Get; set ;}
- Public list <string> teltable {Get; set ;}
- }
- Class Program
- {
- Static void main (string [] ARGs)
- {
- Arraylist Glist = new arraylist ();
- Glist. Add (New guestinfo {name = "Qian zhuowen", age = 20, tel = "110 "});
- Glist. Add (New guestinfo {name = "Wu Guojun", age = 21, tel = "120 "});
- Glist. Add (New guestinfo {name = "", age = 22, tel = "130 "});
- Glist. Add (New guestinfo {name = "monsoul", age = 23, tel = "140 "});
- // Pay attention to the first line of the LINQ query, before G
- VaR query = from guestinfo g in glist
- Where G. age <22
- Select g;
- Foreach (var q in query)
- {
- Console. writeline ("Name: {0} Tel: {1}", Q. Name, Q. Tel );
- }
- Console. Readline ();
- }
- }