Private Sub IsNothing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IsNothing.Click
Dim sl As SortedList = New SortedList
Dim slNull As SortedList = New SortedList
sl.Add("A", "0")
sl.Add("B", "1")
If sl Is Nothing Then
MsgBox("sl is nothing")
Else
MsgBox("sl has elem" & " " & sl.GetByIndex(0).ToString & " " & sl.GetByIndex(1).ToString)
End If
slNull.Add("a", "0")
slNull.Add("b", "1")
slNull = Nothing
If slNull Is Nothing Then
MsgBox("slNull is nothing")
Else
MsgBox("slNull has elem")
End If
End Sub
Dim sl As SortedList = New SortedList
Dim slNull As SortedList = New SortedList
sl.Add("A", "0")
sl.Add("B", "1")
If sl Is Nothing Then
MsgBox("sl is nothing")
Else
MsgBox("sl has elem" & " " & sl.GetByIndex(0).ToString & " " & sl.GetByIndex(1).ToString)
End If
slNull.Add("a", "0")
slNull.Add("b", "1")
slNull = Nothing
If slNull Is Nothing Then
MsgBox("slNull is nothing")
Else
MsgBox("slNull has elem")
End If
End Sub

本文提供了一个使用VB.NET实现的示例,演示如何检查SortedList集合是否为空。通过实例化SortedList对象并添加元素,然后利用IsNothing方法判断集合是否为空,最后通过GetByIndex方法获取集合中第一个元素进行输出。

被折叠的 条评论
为什么被折叠?



