Is there anything like a struct in dart?

That sounds like a class.

 class MyVector {
   int x;
   int y;
   MyVector(this.x, this.y);
 }

There is no simpler and more efficient way to create a name-indexed structure at runtime. For simplicity you could usually use a Map, but it’s not as efficient as a real class.

A class should be at least as efficient (time and memory) as a fixed length list, after all it doesn’t have to do an index bounds check.

In Dart 3.0, the language will introduce records. At that point, you can use a record with named fields instead of creating a primitive class:

var myVector = (x: 42, y: 37);
print(myVector.x);

A record is unmodifiable, so you won’t be able to update the values after it has been created.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)