Answer the question
In order to leave comments, you need to log in
How to access a property of an instance of a class that is in an array?
I have a loop that creates n instances of a class. This instance has 2 properties that are assigned from the keyboard. As a result, I get a list with objects. How can I get the values of any properties and output/overwrite them in those objects?
int n = Convert.ToInt32(Console.ReadLine());
ArrayList processes = new ArrayList();
for (int i = 0; i < n; i++)
{
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
processes.Add(new Potok
{
ProcComplete = a,
ProcArrive = b
});
}
for(int i = 0; i < n; i++)
{
Console.WriteLine(processes[i]);
}
Answer the question
In order to leave comments, you need to log in
Why not do this:
using System.Collections.Generic;
...
var processes = new List<Potok>()
...
Console.WriteLine(processes[i].PropName);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question