F# 支持类不错,但提供了另一种解决方案,称为对象表达式(object expressions)。这是受函数编程启发,往往是更优雅,因为,创建有用的值之前,我们不必要写任何类的声明。
基于52个网页-相关网页
The following example illustrates several different types of object expressions.
下面的示例阐释了几种不同类型的对象表达式。
You use object expressions when you want to avoid the extra code and overhead that is required to create a new, named type.
若要避免创建新的命名类型所需的额外代码和开销,可以使用对象表达式。
If you use object expressions to minimize the number of types created in a program, you can reduce the number of lines of code and prevent the unnecessary proliferation of types.
如果使用对象表达式来最小化程序中创建的类型数目,您可以减少代码行数,并防止出现不必要的类型增殖。
应用推荐