简体   繁体   中英

System.Collections.Generic.List<T> debugging in quick watch

I have a simple class called SSR2 with one property.

public class SSR2
    {
        public string SSRs { get; set; }
    }

in another class I am instantiating a list of SSR2 and add a new item to it. everything works fine and compile correctly, but int the quick watch something weird happens, or I am missing something. There are two properties which I never seen before : "Capacity" and "Count", and the capacity is set to 4, 3 of them are null.

在此处输入图片说明

Why am I getting this behavior ? normally I am expecting a list with direct access to members like below :

在此处输入图片说明

Thank for your help.

I had the same problem, I fixed it by going to Tools>Options>Debugging>General in Visual Studio, and unchecking "Show raw structure of objects in variables windows".

By unchecking this box you should see the elements of the list as in your second screen shot.

A list is using an array, but abstracts you from the details. It still has a size, and needs to know how many items it has, so when you approach the mad, it can allocate more space for it.

So, having a list of one item is silly, since the next time you want to add you'll have to cart a bigger array. I guess it creates the allocation for four items, and grows as needed later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM