-
Notifications
You must be signed in to change notification settings - Fork 233
Expand file tree
/
Copy pathSortArrayLINQ.cs
More file actions
33 lines (25 loc) · 782 Bytes
/
SortArrayLINQ.cs
File metadata and controls
33 lines (25 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
public class SortArrayLINQ
{
public static void Main()
{
Console.WriteLine("-----------SORTING STRINGS USING LINQ WITH C#-------------");
try{
Console.Write("Enter the number of strings to sort: ");
int numOfStrings = Convert.ToInt32(Console.ReadLine());
string[] words = new string[numOfStrings];
for(int i=0; i<numOfStrings; i++){
Console.WriteLine("Enter String #"+i+": ");
words[i] = Console.ReadLine();
}
var sortedArray = from word in words orderby word select word;
Console.WriteLine("\nSorted List of Strings:");
foreach(string str in sortedArray){
Console.Write(str+" ");
}
Console.WriteLine("\n-------------------------------------------------------");
}catch(Exception){
}
}
}