獲取集合,需要使用多個條件Where,排序OrderBy,查詢Select一起。先來分步實現: source code: string[] stringArray = { "hgdgh", "qerty", "Haktjjy", "zcvz", "rtwrt" }; var contains = E ...
獲取集合,需要使用多個條件Where,排序OrderBy,查詢Select一起。
先來分步實現:
source code:
string[] stringArray = { "hgdgh", "qerty", "Haktjjy", "zcvz", "rtwrt" }; var contains = Enumerable.Where(stringArray, n => n.Contains("t")); var orderby = Enumerable.OrderBy(contains, n => n.Length); var select = Enumerable.Select(orderby, n => n.ToUpper()); var query = select;View Code
source code:
IEnumerable<string> q = Enumerable.Select( Enumerable.OrderBy( Enumerable.Where(new string[] { "hgdgh", "qerty", "Haktjjy", "zcvz", "rtwrt" }, n => n.Contains("t")), n => n.Length), n => n.ToUpper()); q.ForEach(delegate (string str) { Write(str); WriteLiteral("<br />"); });View Code
太於過複雜,當嵌套很多層時,根本不好看。各人習慣之。