List<int> li = new List<int> { 0, 1, 5, 3, 8 }; List<int> newlist = li.Take(3).ToList();
or List<int> li = new List<int> { 0, 1, 5, 3, 8 }; List<int> newlist = new List<int>(); for (int i = 0; i < li.Count; i++) { if (i < 3) newlist.Add(li[i]); }
LINQ语句Takevar result = li.Take(3);
List<int> li = new List<int> { 0, 1, 5, 3, 8 }; List<int> newlist = new List<int>(); for (int i = 0; i < li.Count; i++) { if (i < 3) newlist.Add(li[i]); }
用一句 来实现 那么LINQ是最优雅的了:List<int> li = new List<int>{0,1,5,3,8}; li=li.Take(3).ToList();
List<int> newlist = li.Take(3).ToList();
List<int> li = new List<int> { 0, 1, 5, 3, 8 };
List<int> newlist = new List<int>();
for (int i = 0; i < li.Count; i++)
{
if (i < 3)
newlist.Add(li[i]);
}
List<int> newlist = new List<int>();
for (int i = 0; i < li.Count; i++) { if (i < 3) newlist.Add(li[i]); }
那么LINQ是最优雅的了:List<int> li = new List<int>{0,1,5,3,8};
li=li.Take(3).ToList();
var newLi=li.Take(3).ToList();