Skip to content

Instantly share code, notes, and snippets.

@sebastienros
Created February 27, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastienros/0d685e74b0522c8dc3990a499d40a47c to your computer and use it in GitHub Desktop.
Save sebastienros/0d685e74b0522c8dc3990a499d40a47c to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
public class MyCollection<T> : IEnumerable<T>
{
private readonly List<T> _collection = new List<T>();
public IEnumerator<T> GetEnumerator() => _collection.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
/*
error CS0305: Using the generic type 'IEnumerable<T>' requires 1 type arguments
error CS0305: Using the generic type 'IEnumerator<T>' requires 1 type arguments
error CS0538: 'IEnumerable' in explicit interface declaration is not an interface
error CS0738: 'MyCollection<T>' does not implement interface member 'IEnumerable.GetEnumerator()'. 'MyCollection<T>.GetEnumerator()' cannot implement 'IEnumerable.GetEnumerator()' because it does not have the matching return type of 'IEnumerator'.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment