C#不能通过引用返回this

新手请教各位大神,下面代码期望实现 xx[1][2][3],请问有什么做法可以做到

public ref xxx this[object key] {
    get{
        return ref this;
    }
}

 

 

这是个什么用法、求科普。

所以xx[1][2][3]总是等于xx?那你写这个函数做什么用?

而且你要生成ldelema代码的话,函数类型得是ref readonly

比如

 public ref readonly T this[int index]
        
        {
            get
            {
                if (index >= data.Length)
                    ThrowIndexOutOfRangeException();
 
                return ref data[index];
            }
        }