Stavo leggendo ora il codice prodotto dai compilatori per le varie versioni esposte qui sopra.
Semplificando, con il "Left" viene eseguita la funzione "Left" presente nella classe "Strings" in "Microsoft.VisualBasic.dll". La funzione "Left" ha questo codice:
Come vedi, viene ancora richiamato alla fine il metodo Substring con molti passaggi in più che il richiamo diretto della stessa, ed è qui il degrado di prestazione.codice:Public Shared Function Left(ByVal str As String, ByVal Length As Integer) As String If (Length < 0) Then Throw New ArgumentException(Utils.GetResourceString("Argument_GEZero1", "Length")) End If If ((Length = 0) OrElse (str Is Nothing)) Then Return "" End If If (Length >= str.Length) Then Return str End If Return str.Substring(0, Length) End Function
Ciao![]()


Rispondi quotando