Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I use property to set and get an array?
C++
ref class test{
private:
  stactic array<string^>^my=gcnew array<string^>(5);

public:
  static property array<string^>^MY{//what i need to do here?} 
  
};
Posted
Updated 12-Aug-10 8:39am
v2

1 solution

C++
public ref class Class1
{
private:
    static array<String^>^ _myProperty;

public:
    static property array<String^>^ MyProperty
    {
        array<String^>^ get()
        {
            return _myProperty;
        }

//private: // probably a good idea, depending on your requirements
        void set(array<String^>^ value)
        {
            _myProperty = value;
        }

        //void set(array<String^>^ value);
    }
};

//void Class1::MyProperty::set(array<String^>^ value)
//{
//    _myProperty = value;
//}


The commented code is another valid way to do it. string is not a keyword in C++/CLI as in C#, so you have to use the class name String. You may also consider not having a "public" set accessor for the property since by doing so you're allowing other entities to replace the whole array reference while you probably want to just give them access to the array items (assuming the set method to be setting the backing field). More information regarding properties in C++/CLI is here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900