- //List<T>.Select method
- //Create the data source
- List<int> Scores = new List<int>() { 97, 92, 81, 60 };
- // Create the query.
- IEnumerable<int> queryHighScores = from score in Scores where score > 80 select score;
- // Execute the query.
- foreach (int i in queryHighScores)
- {
- Console.WriteLine(i + " ");
- }
- // Simple data source. Arrays support IEnumerable<T>.
- int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
- // Simple query with one predicate in where clause.
- var queryLowNums =
- from num in numbers
- where num < 5
- select num;
- // Execute the query.
- foreach (var s in queryLowNums)
- {
- Console.WriteLine(s.ToString() + " ");
- }
- //エラ 6 ソス型 'int[]' のクエリ パタンの装がつかりませんでした。'Where' がつかりません。'System.Core.dll' への参照または 'System.Linq' のディレクティブの使用は指定されていますか?
- //解决方法:
- //1.在参照设定中追加System.Core
- //2.使用命名空间:using System.Linq;
- //to be continue......
方便的System.Linq
最新推荐文章于 2024-08-10 07:37:09 发布