Cześć mam problem ze zwracaniem przez funkcję listy obiektów klasy. Moja klasa, funkcja oraz jej wywołanie wyglądają tak:
*Klasa
class Person
{
string Name;
string Surname;
string Email;
string Password;
public Person (string name, string surname, string email, string password)
{
Name = name;
Surname = surname;
Email = email;
Password = password;
}
}
*Funkcja
public List<Person> CreateListOfPeopleFromTxtFile(string peopleListPath)
{
List<Person> peoples = new List<Person>();
List<string> fileLines = new List<string>();
string line;
using (var streamRead = new StreamReader(@peopleListPath))
{
while ((line = streamRead.ReadLine()) != null)
fileLines.Add(line);
}
int i = 0;
foreach (string s in fileLines)
{
string[] split = fileLines[i].Split(new Char[] { ';' });
peoples.Add(new Person(split[0], split[1], split[2], split[3]));
++i;
}
return peoples;
}
*Wywołanie
public Form1()
{
InitializeComponent();
string peopleListPath = "D:\\MojeProgramy\\Test\\PeopleList.txt";
var peopleList = CreateListOfPeopleFromTxtFile(peopleListPath);
}