Doesn't C# Extension Methods allow passing parameters by reference?

前端 未结 3 1157
庸人自扰
庸人自扰 2020-12-03 17:19

Is it really impossible to create an extension method in C# where the instance is passed as a reference?

Here’s a sample VB.NET console app:

Imports          


        
3条回答
  •  执念已碎
    2020-12-03 17:52

    Strange that VB.NET allows this and C# doesn't...

    However, although it might make sense from a technical point of view (since an extension method is just a static method), I think it doesn't feel right, because extension methods are used as if they were instance methods, and instance methods can't modify the this reference.

提交回复
热议问题