For the following line of C# code:
BitArray bitty = new BitArray(new[] {false, false, true, false});
If I evaluate "bitty" in the Watch window, I don't see the members of the collection. If I evaluate "bitty, results", which is supposed to enumerate the IEnumerable and show the results, I get the message "Only Enumerable types can have Results View", even though a BitArray IS an IEnumerable.
Why does the debugger do this?
CLARIFICAITON: I'm asking what is happening inside the VS Debugger Expression Evaluator, NOT asking how to view a BitArray in the debugger..
The results view only works for collections which meet the following conditions:
IEnumerable<T>
orIEnumerable
(VB.Net only works forIEnumerable<T>
)IList
,IList<T>
,ICollection
orICollection<T>
(C# restriction only)DebuggerTypeProxy
attributeIn this case
BitArray
implements bothIEnumerable
andICollection
. The latter disqualifies it from being used with the results view.One way to work around this is to use the
Cast
extension method. This produces anIEnumerable<T>
value from which you can use the results viewThe reason for #2 is a combination of factors:
IEnumerable<T>
.IList/<T>
andICollection<T>
type already have a method that let you view the contentsHence the C# team decided to minimize risk and not add
IEnumerable<T>
to types which they felt already displayed well. VB.Net chose the other direction and will display it for anyIEnumerable<T>
.You might rightfully ask how two teams could look at the same data and make different decisions. It comes down to perspective and of course time. The VB.Net team was very keen on providing a great LINQ debugging experience. VB.Net has a long history of providing a rich debugging + ENC experience and hence was more accustomed / willing to take this type of risk on and additionally had the bandwidth to test it. C# was simply more risk averse, very tight on the schedule and pragmatically decided against it.
Note: My earlier confusion about
IEnumerable
not being supported is because that's actually the case in the VB expression evaluator. The C# expression evaluator does supportIEnumerable
though and by the above rules.