Дан текстовый файл. Напечатать все нечетные строки - C#
Формулировка задачи:
Дан текстовый файл. Напечатать все нечетные строки
Не могу найти ошибку
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace MyProgram
{
class Program
{
static void Main()
{
StreamReader fileIn = new StreamReader("text.txt");
string text=fileIn.ReadToEnd(); //считываем из файла весь текст
fileIn.Close();
string[] lines=File.ReadAllLines(text);
foreach (string line in lines)
{
for (int i=0; i<line.Length; i++)
if (line[i] % 2 == 1)
Console.WriteLine(line);
}
}
}
}Решение задачи: «Дан текстовый файл. Напечатать все нечетные строки»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] lines = File.ReadAllLines("text.txt");
int n = 1;
while ( n < lines.Length)
{
Console.WriteLine(lines[n]);
n += 2;
}
Console.ReadKey();
}
}
}