tailieunhanh - Visual Basic .NET The Complete Reference phần 8

SAlarms mảng có năm yếu tố (0-4), nhưng chỉ số dựa trên là số không, do đó các ràng buộc trên là thực sự 4 và 5 yếu tố không tồn tại. NullReferenceException được nâng lên khi bạn cố gắng để làm việc với một đối tượng mảng đã được khai báo mà không có yếu tố. | Implementing the Container The RemoveAt The method is a variation of the method that can take an Integer to represent the location in the list to remove the node from. This method simply chases up an iterator to land on the node to remove. It makes the target node the CurrentNode and then one of either RemoveFirst RemoveLast or RemovelnBetween. Consider the following definition for RemoveAt Method Name Remove The method removes a node from the list container at the specifed location. Method Signature Public Sub RemoveAt ByVal index As Integer Implements Parameters The method takes an argument of type Object representing the data in the node that will be removed Precondition The method checks the location of the first node representing the data to be removed Postcondition No postcondition Exceptions This method throws two exceptions. It will throw an exception of type ArgumentOutOfRangeException when the index specified does not exist in the list it is thus outside the bounds of the structurethat is below zero and higher than Count . The Catch handler also writes the exception s message to the exceptInfo field which is scoped to BaseNodeCollection. It will also throw an exception of type NodeNotFoundException if the index is 1 indicative of a search turning up negative and returning 1. We can implement RemoveAt as follows Public Sub RemoveAt ByVal index As Integer _ Implements If index 0 Or index Count Then Throw New ArgumentOutOfRangeException End If If index - 1 Then RemoveFirst Return what if the target is at the end of the list ElseIf index 0 Then RemoveLast Return Else what if the target is somewhere between first and last Dim myIterator As Dim intI As Integer While intI index intI 1 End While RemoveInBetween End If Catch ArgExcept As ArgumentOutOfRangeException exceptinfo Catch NodeExcept As .

TỪ KHÓA LIÊN QUAN