All the operations of LINQ are based on the operation of the iteratable object. The simplest is, of course, array processing.
// First example: the simplest example
String [] STRs = {"zhangran", "zhangxiaoran", "xiaozhangran", "ranxiaozhang", "ranzhangxiao", "xiaoxiaoran "}; vaR Index = from N in STRs where n. startswith ("Z") // Where is the limit operator select N; // select this is a required foreach (string I in index) {console. writeline (I);} console. readkey (); // The variants in the preceding example use methods to query string [] STRs = {"zhangran", "zhangxiaoran", "xiaozhangran", "ranxiaozhang ", "ranzhangxiao", "xiaoxiaoran"}; var Index = STRs. where (n => N. startswith ("Z"); foreach (string I in index) {console. writeline (I );}
Console. readkey ();
// Example 2: sort search results/* string [] STRs = {"zhangran", "zangxiaoran", "zixiaozhangran", "ranxiaozhang", "ranzhangxiao ", "xiaoxiaoran"}; var Index = from N in STRs where n. startswith ("Z") orderby N // other options: orderby descending and orderby n. substring (N. length-1) Select N; foreach (string I in index) {console. writeline (I);} console. readkey (); * // The preceding variant: sort by method/* string [] STRs = {"zhangran", "zangxiaoran", "zixiaozhangran", "ranxiaozhang ", "ranzhangxiao", "xiaoxiaoran"}; // var Index = STRs. orderby (n => N ). where (n => N. startswith ("Z"); // var Index = STRs. orderbydescending (n => N ). where (n => N. startswith ("Z"); var Index = STRs. orderby (n => N. substring (N. length-1 )). where (n => N. startswith ("Z"); foreach (string I in index) {console. writeline (I);} console. readkey ();
*/
// Use of aggregate Operators
/* Int [] ints = {1, 2, 4, 5, 6, 7, 8, 9}; var Index = from N in ints where n> 1 select N; // The foreach traversal console is no longer used here. writeline (index. count (); console. writeline (index. average (); console. writeline (index. min (); console. writeline (index. max (); console. writeline (index. sum (n => n + 1); console. readkey ();*/