Declaring Variables in F#

To learn any new programming language , it is necessary to learn the basics first which includes how to declare and define basic data types .

Below is a sample code snippet demonstrating how to declare some of the basic data type variables in F#

Declaring Variables in F#

open System
[<EntryPoint>]
let main argv = 
    // Integer Variable
    let inti = 7
    // Unsigned Integer
    let unsignedi = 7u
    // Declare Decimal
    let decimali = 1M
    // declare Short
    let shorti = 7s
    // declare Long
    let longi = 5L
    // declare byte
    let bytei = 7y
    // declare bool
    let booli = true
    //declare double
    let doublei = 0.7
    //declare float
    let floati = 10.6F
    // declare character
    let chari = 'G'
    //declare string
    let stringi = "Ginktage.com - Programming and F# Website"
    Console.WriteLine(inti)
    Console.WriteLine(unsignedi)
    Console.WriteLine(decimali)
    Console.WriteLine(shorti)
    Console.WriteLine(longi)
    Console.WriteLine(bytei)
    Console.WriteLine(booli)
    Console.WriteLine(doublei)
    Console.WriteLine(floati)
    Console.WriteLine(chari)
    Console.WriteLine(stringi)

    let retval = Console.ReadLine()
    0 // return an integer exit code

image

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the error message “FileOpenAccessDenied – You do not have permissions to open this file...
  • .NET
  • December 3, 2024
You might have had a situation where your code once worked fine in ASP.NET application but now throws the below...
  • .NET
  • December 3, 2024
C# uses the flower bracket “{” and “}” to identify the block or scope of the function or program ....
  • .NET
  • December 3, 2024