F # Tutorials-hello World

Source: Internet
Author: User
Tags printf visual studio visual studio 2010

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.