Array.Reverse () compared to Enumerable.Reverse <TSource> ()

I have a one-dimensional array of elements declared and initialized as:

string[] SubDirectorylist = Directory.GetDirectories(TargetDirectory); 

I would like to change the participants and find Enumerable.Reverse<TSource>() .

What benefits, if any, do LINQ have inverse implementation of more Array.Reverse() ?

+6
source share
3 answers

System.Linq.Enumerable.Reverse() works with all classes that implement IEnumerable , where System.Array.Reverse() only works with arrays. If you know that you have an array, there is nothing wrong with using System.Array.Reverse() .

+6
source

Besides what Daniel said to System.Linq.Enumerable.Reverse() , it actually creates a copy, it iterates from end to beginning when System.Array.Reverse() performs the transformation.

+10
source

If performance is important to you, use Array.Reverse() . System.Linq.Enumerable.Reverse() has the advantage of working on every IEnumerable, such as arrays, lists, etc.

0
source

Source: https://habr.com/ru/post/893086/


All Articles