Skip to content

Commit fde658a

Browse files
authored
Update README.md
1 parent 2d9e654 commit fde658a

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,54 @@ switch (u.Tag)
563563

564564
## Examples
565565

566+
### Foo
567+
568+
```cs
569+
// sizeof(Foo) == 16 (8 data, 1 tag, 7 padding)
570+
[Union]
571+
public partial struct Foo
572+
{
573+
[UnionTemplate]
574+
private interface Template
575+
{
576+
int A();
577+
float B();
578+
long C();
579+
double D();
580+
}
581+
}
582+
```
583+
584+
### Option
585+
586+
```cs
587+
[Union]
588+
public partial struct Option<T>
589+
{
590+
[UnionTemplate]
591+
private interface Template
592+
{
593+
void None(); // tag is 0
594+
T Some();
595+
}
596+
}
597+
```
598+
599+
### Result
600+
601+
```cs
602+
[Union]
603+
public partial struct Result<T, E>
604+
{
605+
[UnionTemplate]
606+
private interface Template
607+
{
608+
T Ok(); // tag is 1
609+
E Err();
610+
}
611+
}
612+
```
613+
566614
### Shape
567615

568616
[F# Shape](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions#remarks)

0 commit comments

Comments
 (0)