displaying structs in an array using enumerator
Posted
by
Mostaguen
on Stack Overflow
See other posts from Stack Overflow
or by Mostaguen
Published on 2012-11-04T15:40:12Z
Indexed on
2012/11/04
17:00 UTC
Read the original article
Hit count: 219
In an object I have :
public IEnumerable<voiture> recup_voitures()
{
foreach (voiture v in _arrVCollection)
{
yield return (v);
}
}
voiture
being a struct and _arrVCollection
being an array containing some struct voiture.
In my main class I have :
foreach (CarCollection.voiture o in collection.recup_voitures())
{
//some code to display the content of each struct
}
What is happening is that if I have an array of length 5 and only 1 struct voiture in it, it will do the displaying code 5 times instead of only 1. What am I doing wrong?
© Stack Overflow or respective owner