Console input and output in F#

Console input and output in F# is demonstrated with the following console application.

// Program.fs

module Program

open System

// Declare the main function
let main() =
    // Ask the user for input
    Console.Write("Enter your input: ")

    // Read user input
    let input = Console.ReadLine()

    // Print the entered input
    Console.Write("You entered: {0}", input)

    // Used for pausing the console application
    Console.ReadLine() |> ignore

// Execute the main function
main()

Output:

Enter your input: foo
You entered: foo

Alternatively, you can use the printfn function for console output.

This entry was posted in F# and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?