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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply