fight90

Problem 1. Odd Lines

Feb 3rd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace Problem_1.Odd_Lines
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             using (StreamReader stream = new StreamReader("Program.cs"))
  15.             {
  16.  
  17.                 /*
  18.                  Write a program that reads a text file and prints on the console its odd lines.
  19.                  Line numbers start from 0. Use StreamReader.
  20.                  */
  21.                 int counter = 0;
  22.                 string str = string.Empty;
  23.                 while ((str = stream.ReadLine()) != null)
  24.                 {
  25.                     if (counter % 2 ==1)
  26.                     {
  27.                         Console.WriteLine(str);
  28.                     }
  29.                     counter++;
  30.                 }
  31.  
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment