What is the equivalent in F# of the C# default keyword?

Stringer picture Stringer · Feb 11, 2010 · Viewed 10.1k times · Source

I'm looking for the equivalent of C# default keyword, e.g:

public T GetNext()
{
    T temp = default(T);
            ...

Thanks

Answer

blu picture blu · Feb 11, 2010

I found this in a blog: "What does this C# code look like in F#? (part one: expressions and statements)"

C# has an operator called "default" that returns the zero-initialization value of a given type:

default(int) 

It has limited utility; most commonly you may use default(T) in a generic. F# has a similar construct as a library function:

Unchecked.defaultof<int>