Sign in to follow this  
I Am Legend

Giving objects in arrays properties

Recommended Posts

A Win32 menu or what? I have never dealt with any time of menu, so I'm probabaly clueless. If it's a custom menu you wrote, I guess make a class called MenuItem and in it, have the public variables things like int width; int height; string text, and other properties you want. Then make an array of MenuItem so when you add something to that array, also set the properties of it you want. I could be completely off and not help at all, but w/e lol.

Share this post


Link to post
Share on other sites
I'm used to C++, but does C# have #include <vector>? if so, just to vector<MenuItem*> menuItems; to make an array of menuitem pointers. Then to add to it, just do MenuItem* newItem; newItem->property = "whatever"; menuItems.push_back(newItem);

[Edited by - Tenac on July 2, 2008 4:32:25 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by I Am Legend
What you said is exactly what I'm trying to do, but I don't know how to give the objects the values


You specify the object whose value you want to set, in the normal way that you specify an element of an array, and then set its property in the normal way.


myArray[0].foo = 42
^ ^^^^^^^ ^ ^^
| ||||||| + ++---------------------------------------+
| ||||+++-+-------------------------------------+ |
| |||+----+---------------------------------+ | |
| ||| +---------------------------+ | | |
| look at the 0th element | | | |
+------------------------- of myArray, and set its foo to 42.

Share this post


Link to post
Share on other sites
Do you simply mean something like this?


foreach (MenuItem menuItem in menuItemArray)
{
menuItem.Property1 = something;
menuItem.Property2 = somethingElse;
menuItem.Property3 = somethingElse;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this