C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: Lines can begin with the dot. Also, the dot can be used in the same way in an expression or argument.
VB.NET program that uses With statement
Imports System.Text
Module Module1
Sub Main()
Dim builder As StringBuilder = New StringBuilder()
With builder
.Append("Dot")
.Append("Net")
.Remove(0, 1)
Console.WriteLine(.Length)
Console.WriteLine(.ToString())
End With
End Sub
End Module
Output
5
otNet
Note: Pushing an instance expression onto the evaluation stack is fast. I constructed this simple benchmark.
Loops: You can see that the inner loops clear the List instance and add 5 elements to it on every iteration.
And: The second loop uses the With statement. I was unable to find any performance advantage from the With statement.
VB.NET program that benchmarks With
Imports System.Text
Module Module1
Sub Main()
Dim list As List(Of String) = New List(Of String)(5)
Dim sw As Stopwatch = Stopwatch.StartNew
For i As Integer = 0 To 10000000
list.Clear()
list.Add("a")
list.Add("b")
list.Add("c")
list.Add("d")
list.Add("e")
Next
sw.Stop()
Dim sw2 As Stopwatch = Stopwatch.StartNew
For i As Integer = 0 To 10000000
With List
.Clear()
.Add("a")
.Add("b")
.Add("c")
.Add("d")
.Add("e")
End With
Next
sw2.Stop()
Console.WriteLine(sw.Elapsed.TotalMilliseconds)
Console.WriteLine(sw2.Elapsed.TotalMilliseconds)
End Sub
End Module
Output
805.7033 (No With)
807.155 (With)