Search code examples
c#f#defaultkeywordc#-to-f#

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


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

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

Thanks


Solution

  • 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>