- Home /
I want to assign multiple variables without having to type the class on the side every time.
public class newClass
{
int x;
int y;
int z;
}
public newClass _class = new newClass();
void dontWant ()
{
_class.x = 1;
_class.y = 2;
_class.z = 3;
}
void dontWant2 ()
{
_class = new newClass()
{
x = 1,
y = 2,
z = 3
}
}
void want ()
{
_class
{
.x = 1;
.y = 2;
.z = 3;
}
}
Is there any way to do this?
Answer by Bunny83 · Dec 15, 2018 at 12:42 PM
As i started programming back in 1995 with Pascal / Delphi it's one of those features i missed in the beginning as well. However i don't miss it anymore. If you have a long code section and your variable name is too long, you can use a local variable:
void SomeMethod()
{
var c = _class;
c.x = 1;
c.y = 2;
c.z = 3;
}
Though this should only be used if the variable is not directly accessible. Also keep in mind this only works for classes. This does not work for structs / valuetypes like Vector3.
Your answer
Follow this Question
Related Questions
Unity value assignment help 0 Answers
Can I choose what to pass into .getcomponent<{VARIABLE}>(); 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
object assigns but does not show when added to list, or any other var 0 Answers