[英]F# Implement base class
I'm new to F# and I wanted to create an F# Forms Application. 我是F#的新手,我想创建一个F#表单应用程序。 But the Problem that I have at the moment, is that I don't know how to implement a base class.
但是我目前遇到的问题是,我不知道如何实现基类。 In C# I would do it like that
在C#中,我会那样做
namespace Test_Form
{
public class Form1 : Form
{
public Form1()
{
}
}
}
But how do I make it in F# so that my Forms is a module and not a type 但是我该如何在F#中使它成为窗体而不是类型呢?
I already tryed 我已经尝试过了
open System
open System.Windows.Forms
type Form1() =
inherit Form()
but that would result in 但这会导致
public class Form1 : Form
{
public Form1() : this()
{
}
}
Where you would use the constructor method in C# 在C#中使用构造函数方法的位置
public class Form1 : Form
{
public Form1()
{
// Do stuff
}
}
In F#, quoting the docs , 在F#中,引用文档 ,
The do-bindings section includes code to be executed upon object construction.
do-bindings部分包含要在对象构造时执行的代码。
you would 你会
type Form1() =
inherit Form()
do // stuff
For example: 例如:
type Form1() as this =
inherit Form()
do this.Click.Add(fun args -> printfn "%s" <| args.ToString())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.