Why can I apply an indexer to an ICollection in VB.Net, but not in C#

前端 未结 4 1435
一整个雨季
一整个雨季 2021-01-17 10:23

Was converting some code from VB.Net to C#, when I came across this, in some code using the Ionic Zip library:

Dim zipEntry1 As ZipEntry = zipFile1.Entries(0         


        
4条回答
  •  终归单人心
    2021-01-17 11:04

    zipFile1.Entries(0) invokes the so-called Default Query Indexer, which is a little-known feature defined in the VB language specification:

    Default Query Indexer

    Every queryable collection type whose element type is T and does not already have a default property is considered to have a default property of the following general form:

    Public ReadOnly Default Property Item(index As Integer) As T
        Get
            Return Me.ElementAtOrDefault(index)
        End Get
    End Property
    

提交回复
热议问题