Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
CSharp /
20180406bReverse a listYou want to reverse a list without changing the original list. That is, you want to get a reversed copy. var tmp = new List<int> {1, 4, 6, 9}; WriteLine(tmp.Pretty()); // [1, 4, 6, 9] WriteLine(Enumerable.Reverse(tmp).ToList().Pretty()); // [9, 6, 4, 1] WriteLine(tmp.Pretty()); // [1, 4, 6, 9]
Note that it also works with other enumerable objects, not only with lists! Reverse a list in placeIf you want to reverse a list in place, then use this: li.Reverse(); It has no return value and it modifies the list in place. |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |