Search Code Guru

How to reverse a sentence using LINQ

This post is a simple, fun example. In this post, I will show you a neat trick about LINQ. You have to reverse a given sentence using LINQ. For example
Input

I love LINQ

Output

LINQ love I

There are several ways to solve this problem using LINQ. But we are going to use LINQ Aggregate operator which I have already discussed in my post

var sentence="I Love LINQ"
var result=sentence.Aggregate((a,b)=>b +" "+ a);

Post a Comment

0 Comments