Matching this syntax requires two things:
- It needs to implement
IEnumerable (or some other interface that IEnumerable implies), it can also inherit from a base class that implements IEnumerable ) - He needs to implement the
Add(...) method, capable of accepting an int value
Any one of the following class declarations will do:
public class MyClass1 : IEnumerable { public void Add(int i) { } public IEnumerator GetEnumerator() => null; } public class MyClass2 : IEnumerable { public void Add(double i) { } public IEnumerator GetEnumerator() => null; } public class MyClass3 : IEnumerable { public void Add(object i) { } public IEnumerator GetEnumerator() => null; }
There are also many types in which the compiler can automatically assign the int value given above - just 3 different examples.
source share