Foreword: In understanding F # Recently, accidentally see a Japanese tutorial (http://techbank.jp/Community/blogs/gushwell/default.aspx), feel very good, so I hope to share with you, learn.
F # 's learning process, unresolved issues, and failed experiences will be serialized in this blog.
With the environment provided by Visual Studio 2010, we can start learning F # programming. Let's get started! First we'll be a Hello World application. Implemented as follows:
printf "Hello world!"
F6: Compiling, F5: Performing debugging, which is the same as C #, after all, is visual Studio.
With printf, you can output strings on the console. If you want to output after the line can be changed to write as follows.
PRINTFN "Hello world!"
Summary of what we learned today:
Use printf for console output.
Use PRINTFN for line wrapping.
Unlike C #, there is generally no writing such as printf ("Hello world!").
Unlike C #, no semicolon is added at the end of the declaration.
By the way, if it were written as follows:
PRINTFN ("Hello world!")
It is also possible to compile through and correct actions.
How do I make a text column output that contains a variable? The sample code is as follows:
let hello = "Hello world!"
printfn "%A" hello
Where let declares a string variable. Let also reminds me of the basic that I used a long time ago.
The "%A" in PRINTFN should be the specified output format! When executed, the%a is replaced by the value of the Hello variable and displayed as:
"Hello world!"
Please note that the display is accompanied by double quotes. How to get rid of quotes, try using:
Printfn '%s ' Hello
This way, the double quotes are removed when the output is made.
Contact the C language of printf, just the statement can also be written:
let name = "Gushwell"
printfn "%s,Nice to meet you!" name
Try to do the right thing by actually running it.
If it shows a number, it can be written like this:
let num = 10
printfn "num = %d" num
To sum up what we have learned this time:
Use let to declare variables.
You do not need to specify a type when declaring.
printf's output format specifies that it is similar to printf in the C language.
But because it is. NET language, I feel as if I could write as follows as C #.
Printfn "{0},nice to meet you!" name