To help you understand a class first.
A class is a blueprint of what the data will look like. If you were to build, a house for example, you would first make the blueprints. Those prints could be used to make many houses that look that same. The differences in those houses vary in areas such as color, wood, brick, or vinyl, and if is has carpet or not. This is just an example but let's make this house into a class (blueprint) and then let's make several of those houses into actual individual objects; finally let's reference all of those in the same location (using a list).
First let's decide what our house options are, the things that set them apart. It's color, exterior, and with or without carpet. Here we will make color a string (text) for simplicity, the exterior as an enum ( so the options are hard coded), and the carpet or not a bool (true or false).
First let's make the enum since it is separate than a class but used within a class.
public enum Exterior { Brick, Vinyl, Wood }
Now let's make the class (the blueprint).
public class House
{
public string Color { get; set; }
public Exterior Exterior { get; set; }
public bool HasCarpet { get; set; }
}
Now that we have the blue print let's actually make some houses. When we make them we need to have a way to locate them in memory so we assign them to a variable. Let's pretend we are in a console app and this is the first few lines of the main method.
var house1 = new House();
var house2 = new House();
var house3 = new House();
Now we have 3 individual houses in memory and can get to any of them by referencing house1, house2, or house3. However, these houses are still built identical and unfortunately have no color (since the string Color is empty), are default to Brick (since the first enum is Brick), and have no carpet (since HasCarpet defaults to false).
We can fix this by referencing each house object reference and assigning these values like so...
house1.Color = "Red";
house1.Exterior = Exterior.Wood;
We could have given the classes a constructor that required these values as parameters to start with or we can do it a simpler way inline (thanks to the power of C# syntax).
var house1 = new House()
{
Color = "Red",
Exterior = Exterior.Wood
};
We could also give it carpet but since this house isn't going to have any and it defaults to false I've left it out.
Ok, so let's say we have all 3 houses built via our blueprint. Let's now store them together in a List. First we need to make the List into an object and reference that also.
var houses = new List<House>();
Now let's add the houses to the list.
houses.Add(house1);
houses.Add(house2);
houses.Add(house3);
Now houses is a reference to all of our house objects. If we want to get to a house in the list we could use an index (starting at 0) and get that location in the list. So let's say that house2 needs to have carpet but we want to use the list now to reference it. Note: There are quite a few ways to reference the items in a list, this one is elementary.
houses[1].HasCarpet = true;
I did this on my phone, hopefully there are no errors. My intentions are to clearly answer your question and educate and help you better understand classes.
collection, likeList<Customer>.