funkcja zwracająca listę z obiektów klasy

0

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);
        }
0

I co robisz dalej z tą listą?

0

Nie robię nic na linijce

public List<Person> CreateListOfPeopleFromTxtFile(string peopleListPath)

wyskakuje

Inconsistent accessibility: return type 'System.Collections.Generic.List<Form1.Person>' is less accessible than method 'Form1.Form1.CreateListOfPeopleFromTxtFile(string)'	D:\MojeProgramy\Test\Test\Form1.cs	41	29	Test
3

Dodaj public przy klasie Person.

0

Coś pisze, że lista jest mniej dostępna niż form.

0

Dzięki już wszystko działa ;)

0

Czemu w ogole klase Person trzymasz jako skladowa klasy Form1? Wywal ja do osobnego pliku i nie bedziesz mial takich problemow :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1