I am learning C# throught the C# via CLR book. And I come across the following piece of code (simplified to create minimal example):
using System;
public class Program
{
public static void Main(String[] args)
{
string text = "Test";
string reversed = new String(text.Reverse().ToArray());
Console.WriteLine(reversed);
}
}
Before trying to run the code above a compiler tells the following:
'string' does not contain a definition for 'Reverse' and no accessible extension method 'Reverse' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) [Console.NET]csharp(CS1061)
I can not wrap my head where the Reverse
method come from. Was the Reverse
method present in an older version of C#?
Original code is the last page of the Delegates topic (417-418 page).