Posted By

stewshack on 10/14/10


Tagged

csharp Linq


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Reverse a String with LINQ


 / Published in: C#
 

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

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

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

Report this snippet  

You need to login to post a comment.