An other name for union types is discriminated unions.
I was interested what a union type looks and behaves in C#.
I build small demo applcation:
private void nudTest_ValueChanged(object sender, EventArgs e)
{
int x = Convert.ToInt32(nudTest.Value);
if(PsA.resultOfVote(x).IsYes())
{
lblResult.Text = "Yes";
}
if(PsA.resultOfVote(x).IsNo())
{
lblResult.Text = "No";
}
if(PsA.resultOfVote(x).IsMaybe())
{
lblResult.Text = PsA.resultOfVote(x).Maybe1.ToString();
}
{
int x = Convert.ToInt32(nudTest.Value);
if(PsA.resultOfVote(x).IsYes())
{
lblResult.Text = "Yes";
}
if(PsA.resultOfVote(x).IsNo())
{
lblResult.Text = "No";
}
if(PsA.resultOfVote(x).IsMaybe())
{
lblResult.Text = PsA.resultOfVote(x).Maybe1.ToString();
}
}
The object created by F# looked like this:
I called the dll PsA.