You create a class that will represent a row with 2 columns:
public class Foo
{
// obviously you find meaningful names of the 2 properties
public string Column1 { get; set; }
public string Column2 { get; set; }
}
and then you store in a List<Foo>:
List<Foo> _items = new List<Foo>();
_items.Add(new Foo { Column1 = "bar", Column2 = "baz" });
How can I set the DataSource of a Listbox to items? If I do
ListBox1.DataSource = _items;
I’ll see a list of Objects in the Listbox instead of the text that it contains
To access the public members, you would just iterate through the items:
Since your collection is a
List<T>, you can also access the items by index:However, you cannot access the
Fooclasses private members. The entire point of making a member inFooprivate is to prevent access from outside of theFooclass.