Skip to content
Discussion options

You must be logged in to vote

There are proposals underway to completely change how extensions work in C#, including support for more members and possibly (eventually) extension implementation.

See #8696

This is purely hypothetical given the current syntax design, but it could end up looking something like this:

public static class ListExtensions {
    // make a List<T> of disposables also be disposable
    extension<T> (List<T> list) : IDisposable
        where T : IDisposable {

        public void Dispose() {
            // dispose every item in the list
            foreach (T item in list) item.Dispose();
        }
    }
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@huoyaoyuan
Comment options

@HaloFour
Comment options

@333fred
Comment options

@hjrb
Comment options

Answer selected by hjrb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants