F
F
forven2015-09-15 10:54:25
ASP.NET
forven, 2015-09-15 10:54:25

How to create a class that initializes an indefinite number of array elements in its field?

There is a class, there is a field which is an array.
What is the best way to create it?
I'm assuming that we pass values ​​to the constructor and initialize the array in the constructor ?
Or is it not possible, and should we use List ?
Added
------
And how to use get set ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
V Sh., 2015-09-15
@forven

something like:

class test
{
public int[] arr;
public test(int N)
{
  arr = new int[N];
}
}

T
Tsiren Naimanov, 2015-09-15
@ImmortalCAT

look at the sources of the List<> class and the IList<> interface
and find out how the
spoiler sheet works - it works with an array

H
heartdevil, 2015-09-15
@heartdevil

Hello.
Something tells me that you need to implement an iterator. Read
here . If not, please describe the problem in more detail. Then get a more accurate solution Read about get and set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question