Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C#
Tip/Trick

Jumble a string using LINQ

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
6 May 2011CPOL 6.4K  
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:
C#
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:
C#
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();

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Social Group (No members)


Comments and Discussions

 
-- There are no messages in this forum --