C
C#2y ago
Livid

✅ shortcut

what's the shortest way of making a variable? for example:
/// NOT VALID CODE (i think)
Form form() {
Width = 100,
}
/// NOT VALID CODE (i think)
Form form() {
Width = 100,
}
9 Replies
Livid
LividOP2y ago
or
/// NOT VALID CODE (i think)
Form form {
Width = 100;
};

// or

Form form = new() {
Width = 100,
};
/// NOT VALID CODE (i think)
Form form {
Width = 100;
};

// or

Form form = new() {
Width = 100,
};
SG97
SG972y ago
what does making a variable mean
Livid
LividOP2y ago
with properties maybe?
linqisnice
linqisnice2y ago
@Livid if you mean during initialization, constructor invocation is probably the least amount of code
var form = new Form(100);
var form = new Form(100);
Livid
LividOP2y ago
:(
SG97
SG972y ago
$close
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Livid
LividOP2y ago
so there isn't a very short method? so shortest is Form form = new() { Height = 100, }?
linqisnice
linqisnice2y ago
you can create a positional record. Minimal ceremony.
public record Form(double Height);

Form form = new(100);
public record Form(double Height);

Form form = new(100);

Did you find this page helpful?