Questo topic e' stato chiuso dal moderatore.
22/07/11 19:19
Qwertj
Salve a tutti,
Non mi riesco assolutamente a spiegare una cosa:
Nel mio programma chiamo una funzione che accetta due parametri ByVal, glieli passo entrambi. Uno di questi è una lista, quando gliela passo però viene passata invece che come ByVal, come ByRef, e viene modificata. Nonostante sia una proprietà ReadOnly
Il codice è circa questo
Ha un senso?
Non mi riesco assolutamente a spiegare una cosa:
Nel mio programma chiamo una funzione che accetta due parametri ByVal, glieli passo entrambi. Uno di questi è una lista, quando gliela passo però viene passata invece che come ByVal, come ByRef, e viene modificata. Nonostante sia una proprietà ReadOnly
Il codice è circa questo
'Funzione chiamata Private Function DoSomething(ByVal List1 As List(Of String), ByVal List2 As List(Of String)) As String Dim Result As String List1.RemoveRange(0, List2.Count) For Each Element As String In List1 Result &= Element Next Return Result End Function 'metodo "principale" Public Sub DoSomethingElse(ByVal List2 As List(Of String)) Dim AnObject As New AClass("example") 'questo stampa, ad esempio, 7 MessageBox.Show(AnObject.ReadOnlyList.Count) MessageBox.Show(DoSomething(AnObject.ReadOnlyList, List2)) 'questo stampa invece 0 quando List2.Count = AnObject.ReadOnlyList.Count MessageBox.Show(AnObject.ReadOnlyList.Count) End Sub
Ha un senso?
aaa