How to use With statement in VB.NET

2 Answers

0 votes
Imports System.Text

Module Module1

    Sub Main()

        Dim sb As StringBuilder = New StringBuilder()

        With sb
            .Append("VB")
            .Append(".")
            .Append("Net")
            Console.WriteLine(.Length)
            Console.WriteLine(.ToString())
        End With

    End Sub

End Module


' run:
' 
' 6
' VB.Net

 



answered Oct 22, 2018 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim list As List(Of String) = New List(Of String)(3)

        With list
            .Add("VB.NET")
            .Add("C#")
            .Add("Java")
        End With

        For Each item As String In list
            Console.WriteLine(item)
        Next

    End Sub

End Module


' run:
' 
' VB.NET
' C#
' Java

 



answered Oct 22, 2018 by avibootz
edited Oct 22, 2018 by avibootz

Related questions

1 answer 66 views
1 answer 189 views
2 answers 143 views
143 views asked Dec 17, 2023 by avibootz
3 answers 170 views
170 views asked Aug 13, 2022 by avibootz
1 answer 159 views
159 views asked Sep 29, 2018 by avibootz
2 answers 190 views
190 views asked Sep 23, 2018 by avibootz
1 answer 228 views
...