I have a class named Documents
I have a collection named class StoreObjects:List<Documents>
I am entering data into the collection from a Form1
"this is part of the code in Form1"
StoreObjects so = new StoreObjects();
d = new Documents(txtName.Text, txtSurname.Text, txtTitle.Text);
so.Add(d);
so far I managed to enter data and even display it.
What I want now is from Form2, I want to be able to search by title, if I do it from Form1 this works but from Form2 does not work
so.SearchByTitle(txtTitle.Text);
Console.WriteLine(so.foundTitle);
if (so.foundTitle == false)
{
Console.WriteLine("Not Found");
}
this is what i have in StoredObject
public bool SearchByTitle(string aTitle)
{
foreach (Documents d in this)
{
if ((d != null) && (d.Title == aTitle))
{
foundTitle = true;
Console.WriteLine(d.GetData());
}
}
return foundTitle;
}
I think that it is because of this declaration in Form 2
StoreObjects so = new StoreObjects();
how can I manage to get the results I want