Frage

Ich habe eine Typenperson wie folgt erstellt, die gut läuft. generasacodicetagpre.

aber wenn ich versuche, eine Liste der Person wie folgt zu erstellen. generasacodicetagpre.

Es gibt den Fehler: Es stehen keine Konstrukteure für den Typ 'List <' A> ' zur Verfügung

kann jemand bitte erklären, was ist das problem?

danke.

War es hilfreich?

Lösung

In F#, the name List<_> is used to refer to the immutable F# list (defined in F# core library).

If you want to create mutable .NET list (System.Collections.Generic.List<_>), you need to use an alias that is defined in the F# library ResizeArray<_> (or you need to use fully qualified name):

let people =  
    new ResizeArray<_>(  
        [| 
            {First = "Bhushan"; Last = "Shinde"}  
            { First = "Abhi"; Last = "Jad"} 
        |]) 

If you want to create a normal F# list (and use it in a functional style), then you can just use the list comprehension syntax without passing the value to any constructor:

let people =  
        [ {First = "Bhushan"; Last = "Shinde"}  
          { First = "Abhi"; Last = "Jad"} ]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top