Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to access property of a class instance, which lies in the mountains? - Q&A

How to access property of a class instance, which lies in the mountains?

0 like 0 dislike
I have a loop that creates n instances of the class. In this instance there are 2 properties whose values are assigned from the keyboard. In the end I get list with objects. How can I get the values of any properties and display/overwrite them in these 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]); }
asked by | 47 views

2 Answers

0 like 0 dislike
Why not do this:
using System.Collections.Generic; ... var processes = new List() ... Console.WriteLine(processes[i].PropName);
answered by
0 like 0 dislike
In this work, initially did not take separate brackets processes[i] and did not specify the type, so did not work.
for(int i = 0; i < n; i++) { Console.WriteLine(((Potok)processes[i]).PropName); }
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


12.7k users

24,788 questions
46,220 answers
12,715 users