zoukankan      html  css  js  c++  java
  • Multi constructor for classes in F#

    When we define an F# class in explicit way, it's easy for new F# programmers to make this kind of mistakes when they define mult constructors: people will forget to initliza the class first before use it.

    type myCls() = 
        //This this a new feature in VS2012,define a property is much easier than before.
        member val Value = 0 with get,set
    
        member this.Print() =
            printfn "%d" this.Value
    
        //Must initilaize the second construct by the default one before set the property Value
        new(value : int) as this = 
            new myCls()
            then
                this.Value <- value

      

  • 相关阅读:
    集合
    字典
    元组
    列表
    数字类型和字符串类型
    Python 数据类型
    jq的一点点
    常用到jq的ajax
    上传
    下载
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/2758794.html
Copyright © 2011-2022 走看看