How to do a multiple definition of variables in VB.Net

1
Hello, I usually program on the web I'm venturing into VB.net (of free and spontaneous pressure ...) and in both Typescript and Javascript and even in PHP, I have the habit of doing a multiple definition of variables. Example:

var a, b, c;
// definição singular de dados
a = '';
b = '';
c = '';
// definição múltipla de dados
a = b = c = '';

I understand that I can not directly compare Javascript with VB.NET because JS is not a strongly typed language, but such a definition also works in VB. My problem is that when I have a component that has an attribute of it of type string, and I make such a statement, it gives me a boolean value, like this:

Public Class Foo
    Public text As String
End Class

Dim a, b, c As New Foo
' definição singular de dados
a.text = ""
b.text = ""
c.text = ""
' definição múltipla de dados
a.text = b.text = c.text = ""

In my opinion (logically speaking) the language should define c.text as an empty string, then b.text as the value of c.text and at the end do the same with a.text how can I make a multiple set like in the example above, having the same value for all three variables?

    
asked by anonymous 26.02.2018 / 20:22

2 answers

1

As it is in your question, it does not work, because as you said it is not possible to compare with other languages, but there are means of attributions that will work as equal assignments for each instance created:

Dim a, b, c As New Foo With {.text = ""}

or even initialize the .text property with "" like this:

Public Class Foo
    Public text As String = ""
End Class

I think it's the best form of assignment when you want to work with variables of the same type, but I particularly like to put each separate statement, but nothing prevents you from doing so for this basic example of your question. >

Running on NetFiddle

    
26.02.2018 / 20:47
1

You can not do this in VB.NET, the maximum it gives is to put everything on the same line, but it will be completely separate assignments.

In fact it is almost always something that should not be done because it is to save typing and not because it should all be the same, only a coincidence makes it the same thing.

    
26.02.2018 / 20:33