I've never done a collection before. I tried to find Solutions on the internet and also with what they had to add for the interfaces to work.
I added everything I could find on the web.
public class RecipeObjectCollection : ICollection<RecipeObject>, IList<RecipeObject>, IEnumerable<RecipeObject>, IEnumerable, IList, ICollection
{
public struct Enumerator : IEnumerator<RecipeObject>, IDisposable, IEnumerator
{
private RecipeObjectCollection collection;
private RecipeObject current;
private int next;
private readonly int version;
public RecipeObject Current => this.current;
...
I obviously could not put everything in the sample code but in the rest of the code there are only inherited functions or methods.
Everything worked without worries, except that I noticed that when I finished filling my collection there was a loop in ICollection.Count and IList.this [int index]
object IList.this[int index]
{
get
{
return this[index];
}
set
{
this.CheckIndex(index);
try
{
this[index] = (RecipeObject)((object)value);
return;
}
catch (InvalidCastException) { }
catch (NullReferenceException) { }
throw new ArgumentException();
}
}
int ICollection.Count
{
get
{
return this.Count;
}
}
In debug mode, I didn't find out why this loop starts and how or if it stops at a time. My program works very well despite this loop. I don't know if it is normal even if I doubt it.
I can add code or anything else if it lacks what can be given an answer or at least a clue.