Why are compound definitions using "var" not allowed?

Well, I really thought this would work (inside the method):

var x, y = 1;

var x = 1, y = 2;

But this is not so, it will not compile - "var is not allowed in the composite definition."

I guess the reason for this is the usual compromise. This is not a very useful feature and, therefore, is not implemented, but we could give and could be in a future release ...

+4
source share
1 answer

Well, if you give it a manifest type:

int x, y = 1;

This declares two int variables and initializes one of them. But to output a local variable of type, an initializer is required to output the type. So you are dead from the gate.

, , . "", , . . , :

var x = 1, y = 2.0;

? x int y float? - , x y? , , -, .

, ? , , . .

, ", , ". , , , , . " "? , ; , , . , ( " " ), .

+12

Source: https://habr.com/ru/post/1694602/


All Articles