dotnet / dotnet/csharplang

Discussion: ref this vs this ref in ref extension methods (15.6, as a 7.2 bug fix)

Open
#1,022 10 comments 26 reactions 1 assignee Assigned to @jcouv View on GitHub
Implemented Needs ECMA Spec Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

Currently `this ref int` is not permitted and you need to use `ref this int` while throughout the language `ref T` denotes a "ref type" and you may add `this` modifier on a parameter to define an extension method, so it would be sensible to use `this ref int` to define a ref extensions method. That being said, the restriction seems arbitrary, both could be allowed but IMO `this ref int` looks more natural based on current rules.

As a minor point, the fact that all extension method's parameter lists start with `this` makes it easier to scan for extension methods in a static class.

LDM:
- https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-12-04.md#this-ref-vs-ref-this

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.