Last active
          December 31, 2015 14:49 
        
      - 
      
- 
        Save hagbarddenstore/8002441 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Variant 1 | |
| var lines = File.ReadAllLines("in.txt"); | |
| var output = new StringBuilder(); | |
| foreach (var line in lines) | |
| { | |
| if (ShouldUseThisLine(line)) | |
| { | |
| output.AppendLine(line); | |
| } | |
| } | |
| File.WriteAllText("out.txt", output.ToString()); | |
| // Variant 2 | |
| string line; | |
| using (var writer = new StreamWriter("out.txt")) | |
| { | |
| using (var reader = new StreamReader("in.txt")) | |
| { | |
| while ((line = reader.ReadLine()) != null) | |
| { | |
| if (ShouldUseThisLine(line)) | |
| { | |
| writer.WriteLine(line); | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment