Dev study and notes

[dart] #25 #4.6 Enums (03:12) 본문

studyLog

[dart] #25 #4.6 Enums (03:12)

devlunch4 2023. 5. 3. 06:12
반응형
enum Team { red, blue }

enum XPLevel { beginner, medium, pro }

class Player {
  String name;
  XPLevel xp;
  Team team;

  Player({
    required this.name,
    required this.xp,
    required this.team,
  });

  void sayHello() {
    print("Hi my name is $name");
  }
}

void main() {
  var lunch = Player(
    name: 'lunch',
    xp: XPLevel.medium,
    team: Team.red,
  )
    ..name = 'john'
    ..xp = XPLevel.beginner
    ..team = Team.blue
    ..sayHello();
  print(lunch.name);
  print(lunch.team);
}

// PRINT
// >>>
// Hi my name is john
// john
// Team.blue
반응형
Comments