开发者

How to create empty class in F#

I know this is stupid question. I can create an empty class like the following in c#.

class Customer{}

But How can I do this in F#? This is my开发者_StackOverflow中文版 try

type Customer() =

   let _ = ()

What is the correct way?


Try

type Customer() = class end

Normally, you can leave the class and end tokens implicit and the compiler infers their presence at the beginning and end of the class's definition, but if the class is completely empty you'll need to specify them. Likewise, you can use struct end and interface end to generate structs and interfaces.


Yet another way:

type Customer = 
  new() = {}


Another way to write an empty class (with a parameterless constructor), and I'm not sure how the resulting IL would look compared to @kvb's solution if different at all, is simply

type Customer() = do ()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜