I am hoping to save lines of code by concatenating a counter ( 0 to 9 ) with the first part of a variable name (num) to identify num0, num1, num2, etc in a loop using XNA. Can I do this ?
|
closed as off topic by Maik Semder, Jonathan Hobbs, Josh Petrie, Jari Komppa, bummzack Nov 8 '12 at 7:38
Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.
|
It's a bit hard to be sure without more context, but it sounds like you should be using an array rather than many individual variables. For example:
However, if your loop is simply iterating over all the elements in your array, it would be cleaner to use the
If this is new to you, I'd suggest reading up on C# arrays. Here are a couple of links to get you started: http://msdn.microsoft.com/en-us/library/9b9dty7d.aspx and http://msdn.microsoft.com/en-us/library/aa288453%28v=vs.71%29.aspx |
|||
|
|