using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace FunkcjaSpilit
{
class Program2
{
static int _MinWordLength = 7;
static void Main()
{
DirectoryInfo filePaths = new DirectoryInfo(@"D:\project_IAD");
FileInfo[] Files = filePaths.GetFiles("*.sgm");
List<int> firstone = new List<int>();
foreach (FileInfo file in Files)
{
int longWordsCount = CalculateLongWordsCount(file, _MinWordLength);
string justFileName = file.Name;
firstone.Add(longWordsCount);
Console.WriteLine(("W pliku: " + justFileName) + " liczba długich słów to " + longWordsCount);
}
Console.WriteLine(firstone.Count);
Console.ReadLine();
}
private static int CalculateLongWordsCount(FileInfo file, int _MinWordLength)
{
return File.ReadLines(file.FullName).
Select(line => line.Split(' ').Count(word => word.Length > _MinWordLength)).Sum();
}
}
}
I this code at line firstone.Add(longWordsCount); I'd like to add all words with length more than 7 to the list, but after running this code, firstone.Add(longWordsCount); adds only sum of files in directory (not the sum of all words with length more then 7 in all .sgm files in directory).
How can I fix it?
Expected results:
firstone.Add(longWordsCount);
should add all words with length more than 7 to the list from all files in the directory.