开发者

where to declare constructor of class in visual studio 2010 winforms project c++?

开发者 https://www.devze.com 2023-04-12 17:48 出处:网络
I nee开发者_如何学Pythond to call methods of class by pressing buttons, but I don\'t want to create new object every time. Besides, class creates list, so I do not want to create list again.If your Ar

I nee开发者_如何学Pythond to call methods of class by pressing buttons, but I don't want to create new object every time. Besides, class creates list, so I do not want to create list again.


If your ArrayList will be used only inside the form class, make it a member of the class and initialize it in the form constructor:

public:
    Form1(void)
    {
        InitializeComponent();

        myList = gcnew ArrayList();
    }
protected:
    ArrayList^ myList;

As Konrad has pointed out, using Generics is preferred over the use of ArrayList. Something like this:

public:
    Form1(void)
    {
        InitializeComponent();

        x = gcnew System::Collections::Generic::List<String^>();
    }
private:
    System::Collections::Generic::List<String^>^ x;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号