Records là kiểu dữ liệu nhẹ, bất biến, cho phép nhóm nhiều giá trị lại mà không cần tạo class.
- Bạn có thể dùng cú pháp vị trí
(String, int)hoặc tên trường({String name, int age}). - Để trả về từ hàm:
(String, int) fetchUser() => ('Alice', 30);và destructure bằngvar (name, age) = fetchUser();. - Records thay thế các workaround dùng Map hay List khi cần trả nhiều giá trị, code ngắn hơn và type-safe hơn.
Records are lightweight, immutable aggregates bundling multiple values (positional or named fields) without needing a class.
Example: (String, int) fetchUser() => ('Alice', 30); then destructure with var (name, age) = fetchUser();. They replace Map/List workarounds for multi-return functions with type-safe, concise syntax.