????? ????? ???? ????? ???? ?? ????? ToArray(type) ???????? 2005 Visual Basic ?? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 312389 - ??? ???????? ???? ????? ????? ??? ???????.
??? ????? ??? ???????. ????? "??? ??" ??? ??? ??????? ??? ????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ??????? Microsoft Visual Basic 2005 ?? Microsoft Visual Basic .NET ?????? ???? ????? ???? ?? ????? ToArray(type). ??? ????? ??? ?????? 2005 Visual Basic ?? Visual Basic .NET ??? ??? ?????? ?????? Strict. ??? ??? ?????? ???? ??????? ????? ???? Visual Basic ??????? ?????? ?????? ?? ???????.

??????? ToArray ??? ??????? ?? ??? ArrayList ?????? ???? ??? ??????. ????? ??????? ????? ??? ??????? ToArray ????? ?????? ???? ??? ?? ??? ????? ??. ??? ???? ??????? ??? ??? ?????? ??? ???????? ??????? ??? ArrayList ??????? ???????? ??? ????? ???? ???????. ???? ??? ??? ??? ???????? System.InvalidCastException ??????? ???????.
Dim custArray() As customer = CType(myArrayList.ToArray(), customer())
				
?????? ???? ????? ???? ??????? ??????? ToArray overloaded ???? ??? ???? ??????. ??? ???? ??????? ???? ??????? ???????.
Dim custArray() As customer = CType(al.ToArray(GetType(customer)), customer())
				
??? ??? ?? ???? ???? ????? ArrayList ?? ??? ??? ??????. ???? ??????? ToArray ??? ????? ????? ArrayList ???????? ??? ????????? ??? ??? ????.

?????? ???? ?????

  1. ??? ???? ??????? "????? ???? ??????" ???????? 2005 Visual Basic ?? Visual Basic .NET. ?????????? ??? ????? ??? ???? Module1.vb.
  2. ??????? ????? ?? Module1.vb ???????? ???????? ???????.
    Option Strict On
    
    Module Module1
    
    
        Sub Main()
            Dim tempCust As customer
            Dim c As New customer()
            c.cname = "anonymous"
    
            Dim al As New ArrayList()
            al.Add(c)
            Dim cArray As Object() = al.ToArray()
            'Display the type of the ArrayList.
            Console.WriteLine(cArray.GetType)
    
            'Uncomment the next line to reproduce the InvalidCastException.
            'Dim custArray() As customer = CType(al.ToArray(), customer())
    
            'Comment the next line to reproduce the InvalidCastException.
            Dim custArray() As customer = CType(al.ToArray(GetType(customer)), customer())
    
            Console.WriteLine(custArray.GetType)
    
        End Sub
    
        Public Class customer
            Public cname As String
        End Class
    
    End Module
    					
  3. ???? CTRL + F5 ?????? ??????? ???????. (CTRL + F5 ???? ???? ???? ?????? ?? ???? ??????.)
  4. ????? ????? ??????? InvalidCastException ? ???? ????????? commenting ????? ?? ????? ???????? ????????.

???????

???? ???????: 312389 - ????? ??? ??????: 28/???? ??????/1435 - ??????: 3.3
????? ???
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
????? ??????: 
kbnosurvey kbarchive kbmt kbvs2005swept kbvs2005applies kbhowtomaster KB312389 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????312389

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com