Witam, mam problem ze zwróceniem listy razem z jej zawartością z klasy do forma, po skończeniu pobierania pliku w klasie uruchamia się metoda mająca na celu sprawdzenie wszystkich plików .txt i dodanie ich do listy.
Tutaj dodaje elementy do listy.
public List<string> VersionList = new List<string>();
string[] files = Directory.GetFiles(pathToFolder, "*.txt");
List<string> found = new List<string>();
foreach (var item in files)
{
string pathToReplace = item;
string cutPath = pathToReplace.Replace(pathToFolder+ @"\", "");
using (StreamReader file = new StreamReader(item))
{
while ((line = file.ReadLine()) != null)
{
if (line.Contains("Version="))
{
VersionList.Add(resultVersion);
}
}
}
I tu gdy MessageBoxem sprawdzałem liczbę elementów to wszystko było dobrze ale gdy chciałem w metodzie zwrócić listę była ona 0.
public IList<string> ReturnList()
{
MessageBox.Show(VersionList.Count.ToString());
return VersionList;
}
Następnie w formie:
private void listView3_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (var item in reloadClass.ReturnList())
{
iniList.Add(item);
}
Niestety nie zostaje nic dodane ponieważ z klasy zwraca mi 0.