Mega Code Archive

 
Categories / C# Tutorial / LINQ
 

Sorting strings in a file

using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Xml.Linq;     class Program     {         static void Main(string[] args)         {             List<string> strs = new List<string>();             using( StreamReader sReader = new StreamReader("data.txt"))             {               string str;               str = sReader.ReadLine();               while (str != null)               {                 strs.Add(str);               }             }             IEnumerable<string> i = from name in strs orderby name descending select name;             foreach (string nam in i)             {               Console.WriteLine(nam);             }         }     }