F# Example: Hello WorldIn F# programming language, a simple "hello world" program can be written by multiple ways. Let's see the top 4 ways to create a simple F# example:
F# Simple Example using printfnOutput: Hello World! Here, printfn is a function that prints formatted output on the console. F# Example: using System.ConsoleWe can write the first F# program using System.Console.WriteLine() method like C#. Here, System is a namespace, Console is a class and WriteLine is a method. Output: Hello World F# Example: using open SystemIf we write open System, it means we don't need to specify System namespace for accessing any class of this namespace like Console etc. Here, we are using Console class without specifying System.Console. Output: Hello World F# Example: using classOutput: Hello World! Descriptiontype: It is a keyword which is used to define type in F#. Program: It is a name of type class. A class is a blueprint or template from which objects are created. It can have data members and methods. class: It is a keyword which is used to create class type. It is optional. do: It is a keyword which is used to execute independent code. printf : It is a function which is used to produce formatted output. end: It is used to end declaration of a class. It is optional. new: It is a keyword which is used to create object for the specified class. F# Example: using functionOutput: Hello World! Descriptionlet: Here, let is a keyword which is used to declare variable or function. program: It is a name of function. printf: It is a function which is used to produce formatted output. program: The last "program" statement is used to call program function.
Next TopicData Types in F#
|