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 59 views
1 answer 178 views
2 answers 135 views
135 views asked Dec 17, 2023 by avibootz
3 answers 155 views
155 views asked Aug 13, 2022 by avibootz
1 answer 153 views
153 views asked Sep 29, 2018 by avibootz
2 answers 181 views
181 views asked Sep 23, 2018 by avibootz
1 answer 222 views
...