Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20180406b

Reverse a list

You 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]

list.Pretty() is simply responsible for pretty printing a list (find its source here). Enumerable.Reverse() returns an iterator.

Note that it also works with other enumerable objects, not only with lists!

Reverse a list in place

If 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.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2018 May 07, 12:26