Mam 2 formy i klasę osoba, w pierwszej tworzę listę obiektów klasy osoba, klikając przycisk otwieram formę Szukaj i usiłuję przekazać listę obiektów do formy Szukaj. W kodzie wyskakuje mi błąd niespójność dostępności. Jeżeli przekazywana lista jest typu string wszystko działa tak jak trzeba. Jak przekazać listę obiektów?
kod Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kontakty
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<osoba> lista = new List<osoba>();
lista.Add(new osoba(1, "waldek"));
lista.Add(new osoba(1, "beata"));
Szukanie frm2 = new Szukanie(lista);
frm2.Show();
}
}
}
kod formy Szukanie
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kontakty
{
public partial class Szukanie : Form
{
public Szukanie(List<osoba> lista)
{
InitializeComponent();
List<osoba> lista3 = new List<osoba>();
lista3 = l;
int x = 0;
}
}
}
kod klasy osoba
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kontakty
{
class osoba
{
public int nr_dostawcy { get; set; }
public string nazwa_dostawcy { get; set; }
public osoba(int numer, string nazwa)
{
nr_dostawcy = numer;
nazwa_dostawcy = nazwa;
}
}
}