Advertisement
striking

Untitled

Dec 29th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. // Write a program that reads a text file containing a list of strings, sorts them and saves them to another text file.
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.IO;
  9.  
  10. namespace _06.SortAndSaveInNewFile
  11. {
  12.     class SortAndSaveInNewFile
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             StreamReader read = new StreamReader(@"..\..\strings.txt");
  17.             List<string> names = new List<string>();
  18.  
  19.             using (read)
  20.             {
  21.                 names.Add(read.ReadToEnd());
  22.             }
  23.  
  24.             foreach (var item in names.OrderBy(x => x.Length))
  25.             {
  26.                 Console.WriteLine(item);
  27.             }
  28.             Console.WriteLine();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement