LINQ in C# - Examples - Reverse- Ordering

  • The reverse operator outputs a sequence of the same type as the input sequence but in the reverse order.
  • It returns void 
  • Example
class Point
    {
        public int x { get; set; }
        public int y { get; set; }       
    }
    class Program
    {      
        static void Main(string[] args)
        {
            List<Point> Points = new List<Point> {
                                    new Point(){ x=10, y=20 },
                                    new Point(){ x=-1, y=23 },
                                    new Point(){ x=-4, y=-9 },
                                    new Point(){ x=50, y=67 },
                                  
                                 };

            Points.Reverse();

            foreach  (var item in Points)
            {
                Console.WriteLine($"{item.x} {item.y}");
            }
            Console.ReadLine();
        }
    }
//Output
50 67
-4 -9
-1 23
10 20

No comments:

Post a Comment

Framework Fundamentals - String - Comparing Strings

In comparing two values, the .NET Framework differentiates the concepts of equality comparison and order comparison . Equality compariso...