Query arraylist by LINQ (when the data type is weak)

Source: Internet
Author: User

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:
  1. Public class guestinfo
  2. {
  3. Public string name {Get; set ;}
  4. Public int age {Get; set ;}
  5. Public String Tel {Get; set ;}
  6. Public list <string> teltable {Get; set ;}
  7. }
  8. Class Program
  9. {
  10. Static void main (string [] ARGs)
  11. {
  12. Arraylist Glist = new arraylist ();
  13. Glist. Add (New guestinfo {name = "Qian zhuowen", age = 20, tel = "110 "});
  14. Glist. Add (New guestinfo {name = "Wu Guojun", age = 21, tel = "120 "});
  15. Glist. Add (New guestinfo {name = "", age = 22, tel = "130 "});
  16. Glist. Add (New guestinfo {name = "monsoul", age = 23, tel = "140 "});
  17. // Pay attention to the first line of the LINQ query, before G
  18. VaR query = from guestinfo g in glist
  19. Where G. age <22
  20. Select g;
  21. Foreach (var q in query)
  22. {
  23. Console. writeline ("Name: {0} Tel: {1}", Q. Name, Q. Tel );
  24. }
  25. Console. Readline ();
  26. }
  27. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.