0

This is probably a stupid question, but here goes. I have this statement in my program:

 // No node should be shown as selected
 mdxTreeList.Selection.Set(new TreeListNode[0]);

The variable mdxTreeList is an instance of the DevExpress XtraTreeList.TreeList control, and TreeListNode is the name of another DevExpress class. But what exactly does the syntax "new TreeListNode[0]" mean? I would have thought it was a syntax error, but it works fine. (If I remember right, this statement originally came from a DevExpress sample program.)

RenniePet
  • 11,420
  • 7
  • 80
  • 106

2 Answers2

4

That's just an array of type TreeListNode[] with zero elements.

e_ne
  • 8,340
  • 32
  • 43
4

It's a one-dimensional array with zero length (i.e. zero members). The type is TreeListNode[].

Some people prefer to write the same thing as new TreeListNode[] { } but that's just a matter of taste.

By the way, since static indexers are not allowed in C#, there's no possibility this could be an indexer access. (Of course indexers are meant to "look like" arrays, so it is not by accident that both use square bracket [] syntax.)

Community
  • 1
  • 1
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
  • Thanks for your extra comments. Brain glitch on my part, feeling very embarrassed. Only excuse I have is that I had just tried to create a new TreeListNode object with "new TreeListNode()", and that failed, saying the constructor was internal, and then I happened to notice this statement where "new" and "TreeListNode" were involved and ... oh dear, oh dear. – RenniePet Jan 13 '13 at 19:39