ข้ามไปยังเนื้อหาหลัก
ProgrammerThailand

Flutter

การเรียกใช้ Method ของ Instance ใน Dart

ตัวอย่างการเรียกใช้ method getMe() ของ instance ในภาษา dart

void main() {
  final person = Person(name: 'Manop Kongoon', age: 37, height: 1.75);
  print(person.getMe());
}

class Person {
  Person({this.name, this.age, this.height});
  final String name;
  final int age;
  final double height;
  
  String getMe() => 
    "Hello, I'm $name. I'm $age years old, I'm $height meters tall";
}

ผลลัพท์

Hello, I'm Manop Kongoon. I'm 37 years old, I'm 1.75 meters tall

 

ติดปัญหาตอนทำตาม? ถามในชุมชน

ความคิดเห็น (0)

ยังไม่มีความคิดเห็น — เริ่มคุยเป็นคนแรก ถามสิ่งที่สงสัย หรือแชร์ประสบการณ์ของคุณ