❔ How can I create a fill method that creates unique elements?
I have the following 2D array method that is for basic types and references.
This works when I want basic types and every reference value pointing to the same object. I want to keep this method for those, which is the most common.
However, I need a similar one that makes every element unique using
Here's the idea:
Again, this is just example code of what I want to see happen, but it has a compile error that T does not have a new() constraint. Is there a good solution to this?
For reference, my class is written as this:
This works when I want basic types and every reference value pointing to the same object. I want to keep this method for those, which is the most common.
However, I need a similar one that makes every element unique using
new. For example, every Wall object in the array is unique. Each wall has its own properties. I do want the method generic so it allows any object of a class. Here's the idea:
Again, this is just example code of what I want to see happen, but it has a compile error that T does not have a new() constraint. Is there a good solution to this?
For reference, my class is written as this: