I'm trying to create an event handler and I am getting the error : 'Object' does not contain a definition for ListCountLastH "
and same for listCountLH
.
Changing private List
to public List
makes no difference and I am pretty sure I have to initialise the lists in protected override void OnStateChange()
but anyway public /*override*/ void OnStateChange()
makes no difference, so any help would be greatly appreciated.
public class Incrementer : DivergenceList5m
throws ListCountLastH
and listCountLH
inaccessible due to protection level
DivergenceList5m.ListCountLastH.Add(DivergenceList5m.listCountLH);
throws additionally "An object reference is required for the non-static field, method or property'Namwspace.Class.ListCountLastH "
and same for listCountLH
and I just don't know what else to try...
Thank you
public class Divergence5min : Strategy
{
public int listCountLH;
private List<int> ListCountLastH;
private List<double> LastHSwDMI;
protected override void OnStateChange()
{
ListCountH = new List<int>();
LastHSwDMI = new List<double>();
}
...
protected override void OnBarUpdate()
{
if (!LHsDmiAdd && b > 1 && HSwDMI[b-1] - HSwDMI[b] > 0.001 && HSwDMI[b-1] - HSwDMI[b-2] > 0.001)
{
LastHSwDMI.Add(HSwDMI[b-1]);
listCountLH = LastHSwDMI.Count;
ListCountLastH.Add(listCountLH);
...
}
}
public class Incrementer
{
public EventHandler ItemAdded;
public void AddItem()
{
base.ListCountLastH.Add(base.listCountLH);
if (ItemAdded != null)
ItemAdded(this, null);
}
}
}
Modifying like this with the private List
still throws the 'inaccessible due to its protection level' error. The subscriber class does not throw any errors, though
public class Incrementer : DivergenceList5m
{
public event EventHandler ItemAdded;
public void AddItem()
{
var divList = new DivergenceList5m();
divList.ListCountLastH.Add(divList.listCountLH);
if (ItemAdded != null)
ItemAdded(this, null);
}
}
class AddingItems
{
public int ItemsCount {get; private set;}
public void Items (Incrementer incrementer)
{
ItemsCount = 0;
incrementer.ItemAdded += AddItems;
}
void AddItems (object source, EventArgs e)
{
ItemsCount++;
}
}
Last code version
public class Divergence5min : Strategy
{
public int listCountLH;
public List<int> ListCountLastH;
public List<double> LastHSwDMI;
...
public class Incrementer : DivergenceList5m
{
public event EventHandler ItemAdded;
public void AddItem()
{
var divList = new DivergenceList5m();
divList.ListCountLastH.Add(divList.listCountLH);
if (ItemAdded != null)
ItemAdded(this, null);
}
}
class AddingItems
{
public int ItemsCount {get; private set;}
public void Items (Incrementer inc)
{
ItemsCount = 0;
inc.ItemAdded += AddItems;
}
void AddItems (object source, EventArgs e)
{
ItemsCount++;
}
}