Created
January 30, 2020 06:33
-
-
Save AlexKenbo/53715ce10a25eb3777688ac7beb0c90c to your computer and use it in GitHub Desktop.
Присвоение значений закрытым переменным класса в конструкторе
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student{ | |
var _id; | |
var _name; | |
Student({this._id, this._name}); // error - имена параметров не могут начинаться с _ | |
void set id(int id) => _id = id; | |
void set name(String name) => _name = name; | |
} | |
//Присвоение значений закрытым переменным класса в конструкторе | |
class Student2{ | |
var _id; | |
var _name; | |
Student2({int id, String name}) : _id = id, _name = name; | |
void set id(int id) => _id = id; | |
void set name(String name) => _name = name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment