Structs
Defining Structs
Section titled “Defining Structs”You can define custom data types using the type keyword.
// Type definition with default valuestype Person { str name; int age; str city = "İstanbul";}Creating Instances
Section titled “Creating Instances”You can create instances of your struct using a constructor-like syntax.
// Constructor with named argumentsPerson p1 = Person("Ali", 25, "Ankara");Person p2 = Person(name: "Ayşe", age: 30); // Uses default cityAccessing Fields
Section titled “Accessing Fields”Fields can be accessed and modified using dot notation.
// Access and modifyprint(p1.name, p1.age);p1.city = "İzmir";JSON Conversion
Section titled “JSON Conversion”Structs can be converted to and from JSON.
// Convert struct to JSON stringstr jsonStr = toJson(p1);
// Create struct from JSON stringPerson p3 = fromJson("Person", jsonStr);