Advertisement
vlad0

Text Files 04

Jan 23rd, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace _04.CompareLineByLine
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string firstFileName = "../../mytemp01.txt";//the dir of the .cs file
  13.             string secondFileName = "../../mytemp02.txt"; //the dir of the .cs file
  14.  
  15.  
  16.             CompareTwoFiles(firstFileName, secondFileName);
  17.         }
  18.  
  19.         private static void CompareTwoFiles(string firstFileName, string secondFileName)
  20.         {
  21.             int equalLines = 0;
  22.             int differentLines = 0;
  23.            
  24.             using (StreamReader firstReader = new StreamReader(firstFileName))
  25.             {
  26.                 using (StreamReader secondReader = new StreamReader(secondFileName))
  27.                 {
  28.                     string firstLine = firstReader.ReadLine();
  29.                     string secondLine = secondReader.ReadLine();
  30.  
  31.                     while (firstLine!=null && secondLine != null)
  32.                     {
  33.                         if (firstLine == secondLine)
  34.                         {
  35.                             equalLines++;                
  36.                         }
  37.                         else
  38.                         {
  39.                             differentLines++;
  40.                         }
  41.  
  42.                         firstLine = firstReader.ReadLine();
  43.                         secondLine = secondReader.ReadLine();
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             Console.WriteLine("Total lines: {0}", equalLines+differentLines);
  49.             Console.WriteLine("Equal lines: {0}", equalLines);
  50.             Console.WriteLine("Different lines: {0}", differentLines);
  51.  
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement