struct

Installation
SKILL.md

仓颉语言结构体 Skill

1. 结构体定义

1.1 基本语法

struct Rectangle {
    let width: Int64
    let height: Int64
    public init(width: Int64, height: Int64) {
        this.width = width
        this.height = height
    }
    public func area() { width * height }
}
  • 使用 struct 关键字 + 名称 + {} 体定义
  • 仅可在顶层作用域定义
  • 结构体体内可包含:成员变量、成员属性、静态初始化器、构造函数、成员函数
Installs
5
First Seen
Mar 11, 2026
struct — kong-baiming/cangjie-doc-skills