Getter property with arguments

前端 未结 3 931
情深已故
情深已故 2020-12-29 20:43

I guess I\'ve seen it somewhere before, but now I can\'t remember nor find it. Is there a way to make a getter property with arguments?

I mean, as I can convert "

3条回答
  •  伪装坚强ぢ
    2020-12-29 21:25

    To answer the question: No, it is not possible, and as already pointed out, a getter with a parameter would look just like a method.

    The thing you are thinking about might be an indexed default property, which looks like this:

    class Test
    {
        public string this[int index] 
        {
            get { return index.ToString(); } 
        }
    }
    

    This allows you to index into an instance of Test, like this:

    Test t = new Test();
    string value = t[1];
    

提交回复
热议问题