This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17471|Reply: 1

[Communication] Solve the problem of linq return value being empty or forcing the type to be null

[Copy link]
Posted on 5/9/2015 6:27:11 PM | | |


Today, the egg hurt all afternoon, and the data obtained was anonymously loaded with var.

Then force type conversion, it becomes null, I have been writing a forced type conversion wrong,

Finally, I found some information from the Internet, and finally came out, var type to list type requires toList(), what a trick! !

Correct writing:

  1. var hh = (from f in db.ClassInfo select f).ToList();
  2.                 List<ClassInfo> g = hh as List<ClassInfo>;
  3.                 GridView1.DataSource = g;
  4.                 GridView1.DataBind();
Copy code

  1. public static List<shopinfoview> GetShopInfo() {
  2.             ShopDBDataContext db = new ShopDBDataContext();
  3.             
  4.             return (from b in db.shopinfoview select b).ToList();
  5.         }
Copy code






Previous:A few simple uses of IEnumerable
Next:The school can go online! It's on the Internet!
Posted on 5/9/2015 8:45:03 PM |
learned.      
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com