Toán tử null-aware giúp xử lý giá trị nullable an toàn. ?. truy cập thuộc tính chỉ khi đối tượng khác null: person?.name. ?? cung cấp giá trị mặc định nếu bên trái là null: name ?? "Unknown". ??= chỉ gán nếu biến đang là null: count ??= 0.
Các toán tử này giúp code ngắn gọn và tránh lỗi null.
Null-aware operators safely handle nullable values. ?. accesses properties only if the object is not null. ?? provides a default value if the left side is null. ??= assigns only if the variable is null.
These prevent null errors and reduce boilerplate code.