Corner case in using lambdas expression in base constructor

后端 未结 5 1527
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 08:03

In the Framework we are building we need the following pattern:

public class BaseRenderer
{
    Func renderer;
    public BaseRenderer(Func<         


        
5条回答
  •  有刺的猬
    2021-01-05 08:41

    The C# specification at 7.5.7 says: "A this-access is permitted only in the block of an instance constructor, an instance method, or an instance accessor."

    And even more directly in 10.11.1: "An instance constructor initializer cannot access the instance being created. Therefore it is a compile-time error to reference this in an argument expression of the constructor initializer, as is it a compile-time error for an argument expression to reference any instance member through a simple-name."

    Though the instance has been created according to 7.5.10.

    Hmm. That's actually pretty strange. I did not see any compile-time error.

提交回复
热议问题