List<string> listStr = { “A”, “B”, “C”, “D”, “E”, “F”, “G”};
var query = from n in listStr where 索引从1-3的元素 select n;
查询出索引1-3的内容 BCD
var query = from n in listStr where 索引从1-3的元素 select n;
查询出索引1-3的内容 BCD
解决方案
20
List<string> listStr = new List<string> { "A", "B", "C", "D", "E", "F", "G" }; var q = listStr.Where((s, i) => i >= 1 && i <= 3); Console.WriteLine(string.Join(" ", q));
B C D
20
List<string> listStr = new List<string>() { "A", "B", "C", "D", "E", "F", "G" }; var query = (from n in listStr select n).Skip(1).Take(3);