Code That Says Exactly What It Means

Kagamin spam at here.lot
Thu Oct 30 16:18:19 UTC 2025


> ```
> public struct Enumerator : IEnumerator<T>, IEnumerator
> {
> 	private readonly List<T> _list;
> 	private int _index;
> 	private readonly int _version;
> 	private T? _current;
>
> 	internal Enumerator(List<T> list)
> 	{
> ```

Also notice that Enumerator's constructor has internal access 
attribute, which is broader than needed, because it's intended to 
be called only by the List class, but is callable by any code in 
the library. D can provide better encapsulation here by declaring 
the constructor with private access attribute, which broad enough 
to be callable by the collection, but stricter than C#'s internal.


More information about the Digitalmars-d mailing list