We will see a sample code to generate a string order by(ascending and descending) with inbuilt string Orderby and OrderByDescending.
Eg : input is "dotnetmirror" and we need generate a output like ''deimnoorrrtt" and "ttrrroonmied"
Program
|
class OrderString
{
static
void Main()
{
string
str = "dotnetmirror";
foreach(
char c in
str.OrderBy(x =>x))
{
Console.Write(c);
}
foreach
(char c in
str.OrderByDescending(x => x))
{
Console.Write(c);
}
Console.ReadLine();
}
}
|
Output:
deimnoorrrtt
//ascending order of the string
"dotnetmirror"
ttrrroonmied
//descedning order of the string
"dotnetmirror"
|
0 Comments:
Post a Comment