Reverse a String with LINQ


/ Published in: C#
Save to your folder(s)

Here's how to reverse a string in one line using C# and LINQ.


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Reverse a string
  11. "Star Wars".ToCharArray().Reverse().ToList().ForEach(letter => Console.Write(letter));
  12. }
  13. }
  14. }

URL: http://weblogs.sqlteam.com/mladenp/archive/2006/03/19/9350.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.