65.9K
CodeProject is changing. Read more.
Home

Jumble a string using LINQ

starIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

1.00/5 (1 vote)

Apr 29, 2011

CPOL
viewsIcon

6599

Using LINQ to create a jumbled string.

I came across this question in an interview. The question was a logical one. I have two variables like this:
string value1 = "Demo";
string value2 = "eoDm";
Write code to find set value in value2 as the jumbled word of value1. And here is how to do it:
string value1 = "Demo";
string value2 = "eoDm";
var  valueordered1 = value1.ToCharArray().OrderBy(n => n);
var valueordered2 = value2.ToCharArray().OrderBy(n => n);
Console.WriteLine( valueordered1.SequenceEqual(valueordered2));
Console.ReadLine();