Member Avatar for Falcon25

Hi guys,

I'm really stuck on this. I am not completely familiar with getters and setters so I am having great trouble with this.

Firstly, I am using a windows form application and I have initialised a list within the 'Form1' class. I want to be able to use that list throughout the whole project- so access the contents of the list in my other 3 classes. I've tried making the list Public and I've also tried writing a get / set method, which is shown below- but it still does not work. Any help with this would be greatly appreciated. Thank you

public List<string> StageManagementList
        {
            get
            {
                return stageManagementList;
            }
            set
            {
                stageManagementList = value;
            }
        }

Recommended Answers

All 6 Replies

Easier:

public List<string> StageManagementList {get;set;}

With the method you're showing, you would need a private stageManagementList declared right above that to support it.

...but, yes, that would eventually work.

private List<string> list = new List<string>();
public List<string> List
{
get { return list; }
set { list = value; }
}

Member Avatar for Falcon25

Thank you, it all works well

You are welcome. bye

Please use the one that simply does "get;set;" if you can. Then you don't have to declare a ton of extra variables (.NET 3.5 and up supports this)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.