File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments