This is my first time, so... be gentle ;) Welcome community!
Here's my problem. I have to create multiple objects inside a loop. But I don't know how to do it. Already tried doing it this way:
List<myClass> ObjectList = new List<MyClass>();
and then :
ObjectList.Add(new MyClass(a,b));
Class is with descriptor and params "a" and "b" are set.
So, I'm looking for this :
class myClass
{
int a;
int b;
public MyClass(int A, int B)
{
a=A;
b=B;
}
class Main()
{
Random r=new Random();
MyClass a1 = new MyClass(r.Next(0,11));
MyClass a2 = new MyClass(r.Next(0,11));
MyClass a3 = new MyClass(r.Next(0,11));
MyClass a4 = new MyClass(r.Next(0,11));
MyClass a5 = new MyClass(r.Next(0,11));
MyClass a6 = new MyClass(r.Next(0,11));
}
}
And I have to find a way to create these objects in the loop, cause I cannot know how many of these will be, as I'm reading a matrix from a file.
while(!endOfFile) { }and create each object and add it to the listObjectList.Add(new MyClass(r.Next(0,11), r.Next(0,11)));. As it is shown it's difficult to understand your problem and how we can help to solve it.