2. 限制操作符—【LINQ标准查询操作符】
public class Where_LINQ { public static string ContextString = System.Configuration.ConfigurationSettings.AppSettings["ContextString"].ToString(); public static void Print() { DataContext context = new DataContext(ContextString); Table<Contact> contact = context.GetTable<Contact>(); var whereQuery = from c in contact where c.FirstName.StartsWith("S") select new { c.FirstName, c.LastName, c.EmailAddress }; foreach (var item in whereQuery.Take(10)) { Console.WriteLine(item.FirstName + " " + item.LastName + " " + item.EmailAddress); } Console.WriteLine("\n"); Console.WriteLine("===== Method Syntex ====="); var whereMethodSyntex = contact.Select(con => new { con.FirstName, con.LastName, con.EmailAddress }).Where(c => c.FirstName.StartsWith("S")); foreach (var i in whereMethodSyntex.Take(10)) { Console.WriteLine(i.FirstName + " " + i.LastName + " " + i.EmailAddress); } Console.ReadKey(); } }
【天天来(http://www.daydaycome.com)】- 精选折扣商品,爆料精选,九块九白菜底价尽在天天来!是一个中立的,致力于帮助广大网友买到更有性价比网购产品的分享平台,每天为网友们提供最受追捧 最具性价比 最大幅降价潮流新品资讯。我们的信息大部分来自于网友爆料,如果您发现了优质的产品或好的价格,不妨给我们爆料(谢绝商家)