I am Making a snake game in c++/CLI Windows Form.. and
I need your help to make
Dynamic (System::Drawing::Rectangle) array that increase array->Length when i call some event ...
Inshort is it possible to increase the length of array when i call some event...
1
Expert's answer
2013-02-26T10:07:43-0500
You can't change array size in C++/CLI but there are two possible ways to solve your problem. 1. You can create a new array with a bigger size and copy old array items to it, then add new Rectangle to the end of the new array. (you will do it every time the event is handled so it's not a memory and time-efficient method). 2. You can use collections. First of all declare a private field in your form class: List<System::Drawing::Rectangle>^ rects = gcnew List<System::Drawing::Rectangle>(); and somewhere in your event handler method rects->Add(System::Drawing::Rectangle(0, 9, 4, 5)); simply add new rectangles to your list. And don't forget to import the System::Collections::Generic namespace where the List type is defined: using namespace System::Collections::Generic;
Read more and see how to work with lists in C++/CLI here: https://msdn.microsoft.com/en-us/library/6sh2ey19.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment