Wednesday, February 6, 2008

F# union types in C#

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();
}
}
image
image
image
The object created by F# looked like this:
image
I called the dll PsA.

No comments:

Total Pageviews