Google News
logo
C# - Interview Questions
What is a structure in F#?
The F# structure is a data structure which is used to organize data, and it is value types and efficient than class. It does not allow let binding, so you must declare fields by using val keyword.
 
Example : 
type Book = struct  
   val title : string  
   val author: string  
   val price : float  
   new (title, author, price) =           // Constructor  
      {title = title; author = author; price = price;}  
end  
let book = new Book("FSharp Programming", "Chris Smith", 100.0)   // Calling Constructor  
printfn "Title  : %s " book.title  
printfn "Author : %s"  book.author  
printfn "Price  : $%0.2f"  book.price
Advertisement