I have a bit of a rudimentary question. I have a total of two classes.
I have a few methods inside one class. The skeleton structure is so:
First class is called EvenBetterValueList (public):
public override void AppendAdditionalMenuItems(ToolStripDropDown menu){
// Stuff
}
private void Menu_MyCustomItemClicked(object sender, EventArgs e){
// Stuff
}
protected override void SolveInstance(IGH_DataAccess DA){
// firstList and secondList list<string> declaration
ValueList newList = new ValueList(firstList, secondList);
}
Second class is called ValueList (as you can tell in my SolveInstance method. This too is public):
The skeleton is:
private List<string> _firstList = new List<string>();
private List<string> _secondList = new List<string>();
public List<string> FirstList
{
get { return _firstList; }
}
public List<string> SecondList
{
get { return _secondList; }
}
public ValueList(List<string> firstList, List<string> secondList) {
_firstList.Clear();
_secondList.Clear();
// Add vars to global vars
_firstList.AddRange(firstList);
_secondList.AddRange(secondList);
}
My question is, in SolveInstance of the first class EvenBetterValueList, I am able to use the new instance newList that I've declared. However, I am unable to use this instance in the other methods, like AppendAdditionalMenuItems() or Menu_MyCustomItemClicked().
I would like to access newList inside those two methods, and call things like newList.FirstList[index] or newList.SecondList[index].
The way this abstract class works is that it always called SolveInstance() before anything, I feel this information is quite important.
Is this a scope issue? How do I solve it?
_firstList.AddRange(..)versus_firstList.Add(..)? What's the difference?ValueListclass so it's easier to read for future devs, and there are additional methods below. How do you use.AddRange(..)without a for-loop?_firstList.AddRange(firstList);, for instance. It adds all the values in firstList to _firstList, but you don't have to think about it. If it matters that the elements alternate from the two lists, you could try Linq's aggregate.