Basic input/output syntax

We are now going to see how to write and read in F#. To read and write into the console, we can use the following commands:

  • To write: System.Console.Write("Welcome!")
  • To read: System.Console.Read()
  • To print: printfn "Hello"

Let's compare F# with C#:

                                F#

C#

The F# user is free from the obligation of defining types; for example: let square x = x* x

The compiler can identify (integer * integer) or (float * float) when we pass a value.

 

The C# user is bound to provide a type:

Public int square(int x){ return x = x*x ; }

 

F# has immutable data, and the value never changes; for example: let number = [3;2;1]

let moreNumber = 4:: number

In the preceding example, to add one ...

Get .NET Core 2.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.