user3916664
user3916664

Reputation: 107

How to Assign 1 value to variables(more than 2 variable) at once

Can we assign 1 value to variables(more than 2 variable) at once in VB.net like this :

dim a,b,c,d,e,f,g as string = "A Character"

i can't figure out how to do this.

Upvotes: 1

Views: 127

Answers (2)

Matt Wilko
Matt Wilko

Reputation: 27322

You can't do this if you want separate variable names but you can if you use some sort of Array or List to hold your variables.

The following generates a List(Of String) that contains 5 string elements, each element is holds the value "foo"

 Dim s = Enumerable.Repeat("foo", 5).ToList

Upvotes: 0

HengChin
HengChin

Reputation: 593

If you really need that to be in one line

Dim aChar As String = "MyString"
Dim a, b, c, d As String
a = aChar : b = aChar : c = aChar : d = aChar

Upvotes: 2

Related Questions