Why doesn't Console.Readline work but Console.Readline() does?

why doesn't t
why doesn't it work
why doesn't my
why doesn't he want me
why doesn't this hr department get any respect
it doesn't matter carr
it doesn't matter sonic
it doesn't matter nicholas carr summary

How do you use Console.Readline in F#? Unlike Console.Writeline, it isn't being honored when I call it.

If you use

let s = Console.ReadLine

you are only building a delegate that points to the ReadLine function. You need to say

let s = Console.ReadLine()

to actually execute the function. This is just like C# syntax, except type inference means you don't get a compiler warning.

Why doesn't the Leaning Tower of Pisa fall over?, As information technology's power and ubiquity have grown, its strategic importance has diminished. The way you approach IT investment and management will  Why doesn’t the U.S. use the metric system? Phil Lewis/shutterstock As of today, the entire world has adopted the metric system, with the exception of the United States, Myanmar, and Liberia

What do you mean by "it isn't being honored"? Here's a small console app I've just written in VS2010b1, and it works fine:

open System

let line = Console.ReadLine()
Console.WriteLine("You wrote {0}", line)

// Just to make it pause
let unused = Console.ReadLine()

Are you trying to run the code from F# Interactive within Visual Studio? If so, that may be the issue, as Brian's post explains.

However, I haven't seen the same problem when using F# Interactive from the command line. Here's a complete transcript of a session:

Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version, compiling for .NET Framework Version v4.0.20506

Please send bug reports to fsbugs@microsoft.com
For help type #help;;

> open System;;
> let line = Console.ReadLine();;
Hello world

val line : string = "Hello world"

Running Brian's looping code from F# Interactive didn't show the same problem.

Bottom line: It seems like this is broken in F# Interactive in Visual Studio, but not when running interactively from the command line or in a full console app.

If your computer doesn't recognize your iPhone, iPad, or iPod , And within a year, two of the five remaining senior managers had resigned as well. “It doesn't matter why those two left,” Robinson told Rose between bites of  Why doesn’t He show Himself to each generation of humanity so that everyone on Earth can see and hear Him and know beyond a shadow of a doubt that He is real? After all, according to the Bible, the Lord appeared “to Abraham, to Isaac, and to Jacob, as God Almighty” (Exodus 6:3), and He “spoke to Moses face to face, as a man speaks to

I don't have a Beta1 box handy, but I know that in the past we've had a bug where ReadLine() would see the background commands that communicate between the interactive UI and the background process that runs your F# code. It may be interesting to investigate what

let Foo max =
    let rec Loop i =
        if i < max then
            let line = System.Console.ReadLine() 
            printfn "line = %s" line
            Loop (i+1)
    Loop 1

Foo 12

prints when you highlight it and 'Send to Interactive'. I think possibly you'll see a few unexpected interesting lines, followed by lines you type into the window.

IT Doesn't Matter, It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus,  There are different reasons why it hasn't worked depending on which state you are referring to. But there are several overlapping reasons that apply in whole or in part to each (in what follows I am using &quot;socialist&quot; and &quot;communist&quot; interchangeabl

// is the right way if you're not wanting to use a return of anything typed into readline

Console.ReadLine() |> ignore

Why Doesn't This HR Department Get Any Respect?, The end of credits: why doesn't Netflix want us to watch them? The end credits are an unsexy but important part of the experience – but  Why doesn’t God respond when I cry out, “God, please help me!”? Question: "Why doesn’t God respond when I cry out, ‘God, please help me!’?" Answer: Many have felt abandoned by God in their times of greatest need, asking God for help but not receiving what was asked for.

Why Trump doesn't want to wear a mask - CNN, Why doesn't my board show in the Tools | Serial Port menu ? What if I get a gnu.​io.PortInUseException when uploading code or using the serial monitor (on the  Why is it that America hasn’t gone full-on metric? The simple answer is that the overwhelming majority of Americans have never wanted to. The gains have always seemed too little, and the goal

The end of credits: why doesn't Netflix want us to watch them , Why Doesn't Technology Flow from Rich to Poor Countries? Harold L. Cole, Jeremy Greenwood, Juan M. Sanchez. NBER Working Paper No. 20856. Issued in  With the movement’s attention comes a familiar refrain: Why doesn’t Black Lives Matter focus on “black-on-black” crime? It’s a question asked, in various forms, from Facebook to cable

Troubleshooting, WHY DOESN'T MICROFINANCE WORK? the destructive rise of local neoliberalism Milford Bateman Ø Zed Books L is on II Iron - to Eor its R.H. Why Doesn't  Los Angeles Lakers superstar LeBron James was the latest athlete to share his thoughts about the death of George Floyd and the violent protests going on throughout the country. “Why Doesn’t

  • Yup. Console.ReadLine is a "unit -> string" value. By adding the (), you're passing in the 'unit' that it is expecting as an argument.
  • +1 - This behaviour could be made clearer by requiring a space in front of the (), just like any other argument to a function.
  • You would get a compiler warning! When you make use s. It sounds like you meant to write Console.ReadLine() |> ignore. I would argue that it is C# that does not check whether the output of a function is either captured or ignored.
  • I'm not using it in interactive mode. I'm just building little console apps.
  • Hmmm... that's odd. Is this with the version installed with VS2010b1?
  • Weird. Yesterday I couldn't get it to work no matter what I tried. Now I can't get it to fail, again no matter what I try.
  • I figured it out. "Console.ReadLine()" works. "Console.ReadLine" is silently ignored because it is just building a delegate.
  • "let unused = Console.ReadLine()" would be more F# idiomatic as "Console.ReadLine() |> ignore" - this removes the need for a useless 'let' statement and handles ignoring the return value.
  • Yup, that looks like it could be the problem: when I try that in beta 1, the first line written out is just "line = "
  • The difference is that you are putting empty parens on the end of the ReadLine call and I wasn't.