nadia_dr

Untitled

Jan 13th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. class InsertLineNumbers
  6. {
  7.     // Write a program that reads a text file and inserts line numbers in front of each of its lines.
  8.     // The result should be written to another text file.
  9.  
  10.     static void Main()
  11.     {
  12.         StreamReader reader = new StreamReader("Zada4a.txt");
  13.         StreamWriter writer = new StreamWriter("Result.txt");
  14.         int lineNumber = 1;
  15.         string line = reader.ReadLine();
  16.  
  17.         while (line != null)
  18.         {
  19.             lineNumber++;
  20.             writer.WriteLine("Line {0} {1}",lineNumber,line);
  21.             line = reader.ReadLine();
  22.         }
  23.         reader.Close();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment