Cascading Assignments

usawill

New member
Joined
Jul 13, 2015
Messages
2
Programming Experience
3-5
After some searching, I have come up with a question I hope someone can answer. In Visual Basic, is there a way to do cascading assignments? The reason that I ask this question and not try it for myself is because it yields a compile-time error if you try. This is because VB uses the same operator to do assignments and comparisons. As an example, I want to know if there is a way to do this:

string1 = string2 = "foo"
 
No, there is not. You can do that in C-based languages because an assignment returns a value, i.e. the value that was assigned. Assignments do not return a value in VB so there is nothing to cascade.
 
No, there is not. You can do that in C-based languages because an assignment returns a value, i.e. the value that was assigned. Assignments do not return a value in VB so there is nothing to cascade.

That is what I was afraid of jmcilhinney. Do you know why VB was designed without this feature?
 
That is what I was afraid of jmcilhinney. Do you know why VB was designed without this feature?
My guess would be because VB was designed to be a simple to read language, cascading assignments aren't as quick and easy to read on the screen when scrolling through.
 
Back
Top