# Array literals

> An array literal [a, b, c] is a value: a list you can return, assign, pass as an argument, or supply as a UI prop. Its element type is inferred from the items. Object literals inside it (new T { … }) are plain data, so a render prop like columns: [ new GridColumn<User> { Name = "Email", Value = u => u.Email } ] is fully expressible.

<!-- id: function-collection-literals · area: function · stability: preview · html: https://osysharp.com/reference/function/collection-literals/ -->

## Summary        {#summary}
An **array literal** `[a, b, c]` is a value expression — a list you can return, assign to a local, pass as an
argument, or hand to a UI control as a prop. The element type is inferred from the items (a homogeneous list is the
common case). Because object literals (`new T { … }`) are plain data, a list of them is a first-class value too — so
a UI prop like `columns: [ new GridColumn<User> { Name = "Email", Value = u => u.Email } ]` is expressed directly,
no workaround.

## Signature      {#signature}
```osy syntax
[1, 2, 3]                                     // int[]
["Email", "DisplayName"]                       // string[]
[ new GridColumn<User> { Name = "Email", Value = u => u.Email } ]   // GridColumn<User>[]
[]                                             // an empty list
```

## Description    {#description}
- **A value, anywhere a value fits** — return it, assign it (`var xs = [1, 2, 3];`), pass it as an argument, or use
  it as a render/state value in a component.
- **Element type is inferred** from the items; a list of `new GridColumn<User> { … }` is a `GridColumn<User>[]`,
  matching a prop declared `GridColumn<T>[]`.
- **Object literals inside are pure data.** In a render position a `new T { … }` builds a plain data object (it is
  *not* a stored row — that is what a `new T { … }` inside an action body does). This is why a control's `columns`
  prop takes `[ new GridColumn<T> { … } ]` cleanly.
- **Distinct from set-membership.** Testing membership is written `[a, b].Contains(x)` (or `x in [a, b]`), which the
  compiler lowers to a set test — separate from using `[a, b]` as a value.

## Examples       {#examples}
```osy title="an array literal as a value" test app=collection-literals
int[] Small() { return [1, 2, 3]; }
string[] Names() { var xs = ["Ada", "Grace"]; return xs; }
```

Supplying a control's typed columns from an array of object literals (a UI prop):

```osy title="object literals as a control's typed columns prop" test app=collection-literals-typed-columns
entity User {
  [Required, MaxLength(200)] string Email;
  [Required, MaxLength(120)] string DisplayName;
  security { allow read when IsAuthenticated; }
}

[Page("/users")] [Render(CSR)]
component UsersPage() {
  var users = User.ToList();
  render {
    DataGrid(
      label: "Users",
      rows: users,
      columns: [
        new GridColumn<User> { Name = "Email", Label = "Email", Value = u => u.Email },
        new GridColumn<User> { Name = "DisplayName", Label = "Name", Value = u => u.DisplayName }
      ]
    );
  }
}
```

## See also       {#see-also}
- [List indexer](https://osysharp.com/reference/function/list-indexer/) — reading an element by index (`xs[0]`)
- [List OrderBy (in-memory)](https://osysharp.com/reference/function/list-orderby/) — sorting a collection
- [control — foreign UI controls (charts, grids, maps)](https://osysharp.com/reference/ui/controls/) — foreign controls, whose typed props often take an array literal
