+ 1
serial production of objects in c#
I don't know any method of creating new objects in a for-loop. Example: i want to create a chessboard and need 64 tiles. In a for-loop I could use the count-variable to create objectname+counter as a new object. So far I write or Copy&Paste 64 lines of code. https://code.sololearn.com/ctEsx0DR1lKl/?ref=app
3 Antworten
+ 2
Use arrays! Thats exactly what they are made for. A chessboard can be represented by a two dimensional array of Tiles (8x8)
+ 2
It is actually quitte nice code.
You already using array.
Be aware of the fact that you are allowed to do this. The same you did for displaying the board.
Feld[0,0]= new Tile("T");
If you do that you can create a loop for creating the objects.
Use reference array's to paste in the figur.
+ 2
Thanks a lot to both of you!
I still forget that it's not "a Name", but a reference that points to the created object. So I do not need to have a name, only an "accesspoint" as the array. Wonderful and easy :-)
https://code.sololearn.com/cIh9kcK1IFYl/?ref=app