Does list.count physically iterate through the list to count it, or does it keep a pointer

后端 未结 5 1932
臣服心动
臣服心动 2021-01-11 12:55

I am stepping through a large list of object to do some stuff regarding said objects in the list.

During my iteration, I will remove some objects from the list depen

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 13:39

    You can use a decompiler, such as the freely-available ILSpy, to answer these questions. If you're referring to the List type, then the Count getter simply involves reading a field:

    public int Count
    {
        get { return this._size; }
    }
    

提交回复
热议问题