D
dtarczynski
Hello all.
I have to implement IEnumerator interface in my (static) class. But
compilers throws me an error:
'GetEnumerator': cannot declare instance members in a static class
For example:
private static List<Product> _productsList;
public static List<Product> ProductsList
{
get
{
if (_productsList == null)
_productsList = new List<Product>();
return _productsList;
}
set { _productsList = value; }
}
public IEnumerator GetEnumerator()
{
foreach (Product p in _productsList)
{
yield return p;
}
}
That's why I have question: Can I implement Iterator with static
classes other way?
Thanks in advance
I have to implement IEnumerator interface in my (static) class. But
compilers throws me an error:
'GetEnumerator': cannot declare instance members in a static class
For example:
private static List<Product> _productsList;
public static List<Product> ProductsList
{
get
{
if (_productsList == null)
_productsList = new List<Product>();
return _productsList;
}
set { _productsList = value; }
}
public IEnumerator GetEnumerator()
{
foreach (Product p in _productsList)
{
yield return p;
}
}
That's why I have question: Can I implement Iterator with static
classes other way?
Thanks in advance