2010-08-13 76 views
1

有問題理解委託錯誤。表達期望錯誤,我該如何解決?謝謝你的幫助。委託函數.net

這裏是有問題的行(#259)....

mylist.ForEach(Delegate Function(P As linkItem) As System.Char[]) 

這裏是整個代碼。

<script language="VB" runat="server"> 

    Function sectionTitle(ByRef f As String) 

     'Open a file for reading 
     'Dim FILENAME As String = Server.MapPath("index.asp") 
     Dim FILENAME As String = f 

     'Get a StreamReader class that can be used to read the file 
     Dim objStreamReader As StreamReader 
     objStreamReader = File.OpenText(FILENAME) 

     'Now, read the entire file into a string 
     Dim contents As String = objStreamReader.ReadToEnd() 

     'search string for <title>some words</title>  
     Dim resultText As Match = Regex.Match(contents, "(<title>(?<t>.*?)</title>)") 
     'put result into new string 
     Dim HtmlTitle As String = resultText.Groups("t").Value 

     Return HtmlTitle 

     ' If HtmlTitle <> "" Then 
     'Response.Write(HtmlTitle) 

     ' Else 
     'Response.Write("<ul><li>b: " & contents & "</a></li></ul>") 

     ' End If 

    End Function 


    Public Class linkItem 

     Public myName As String 
     Public myValue As String 

     Public Sub New(ByVal myName As String, ByVal myValue As String) 


      Me.myName = myName 

      Me.myValue = myValue 


     End Sub 'New 

    End Class 'linkItem 



    Sub DirSearch(ByVal sDir As String) 

     Dim d As String 
     Dim f As String 
     Dim mylist As New List(Of linkItem) 


     Try 
      For Each d In Directory.GetDirectories(sDir) 
       'Response.Write("test c") 

       For Each f In Directory.GetFiles("" & d & "", "index.asp") 

        'Response.Write("test a")     
        Dim sTitle As String = sectionTitle(f) 
        'remove wilbur wright college - from sTitle string 
        sTitle = Regex.Replace(sTitle, "My College - ", "") 
        'print section title - must come before search n replace string 
        f = Regex.Replace(f, "C:\\inetpub\\wwwroot\\pathtosite\\", "") 
        'add to list 
        mylist.Add(New linkItem(f, sTitle)) 
        'print links as list 
        'Response.Write("<ul><li><a href='" & f & "'>" & sTitle & "</a></li></ul>") 
        mylist.ForEach(Delegate Function(P As linkItem) As System.Char[]) 
        If (True) Then 
         Response.Write("<ul><li><a href='" & P.myValue & "'>" & P.myName & "</a></li></ul>") 
        End If 


       Next 
       DirSearch(d) 
      Next 
     Catch excpt As System.Exception 
      'Response.Write("test b") 
      Response.Write(excpt.Message) 
     End Try 
    End Sub 




</script> 
<%  
    'Dim sDir As New DirectoryInfo(Server.MapPath("")) 

    Call DirSearch((Server.MapPath(""))) 
%> 

回答

3

這取決於你正在嘗試做什麼。你缺少功能體。但是你可能需要到該行更改爲類似這樣:

mylist.ForEach(AddressOf ProcessLink) 

然後,你需要創建一個子,像這樣:

Sub ProcessLink(li As linkItem) 
    ' Do stuff here 
End Sub 
0

委託缺少的功能代碼執行(如@ Yogendra表示)以及VB.Net不理解char []。也許你的意思是char()。