Im new to the C# language and I have now advanced to lists.
I placed a few lines of code below and here is my question: If every needed object I make I want to keep and I use a List<> then every time I must supply a unique object name(reference). So if Lists were made to replace arrays when possible, how then would C# program create unique names to create objects and then store them in a List<> at run-time?
Not included in the snippet is the student class that has a method() to enter the name, ____,height etc of each student.
After running this code of course all reference the last objetc and thus all are the same. An array[x] by the very nature of using x to index it becomes a unique name at run time. Below I could use s1,s2,s3 for each object but not very practical for real world. Some one please explain how this is done in real world, please.
namespace ConsoleApplication1
{class Program
{static void Main(string[] args)
{List<student> stdb = new List<student>();
student st = new student();
st.enterstudent(
"John Miller", 44, 1, 69, 190); stdb.Add(st);
st.enterstudent("Robert Sanchez", 38, 1, 70, 160); stdb.Add(st);
st.enterstudent("Jim Goalten", 71, 1, 65, 145); stdb.Add(st);
foreach(student x in stdb) student.display(x);
}
}
}