Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用只读属性是否有区别:
type T(arg) = member x.M = arg
并使用自动实现的属性:
type T(arg) = member val M = arg
假设arg没有副作用?有什么理由比另一个更喜欢一个吗?
arg
它们之间的本质区别在于member val表示在实例初始化期间仅计算一次的表达式。所以,
member val
type Person(fname, lname) = member val Name = fname + lname // would be calculated once
所以,首先要考虑的是性能。
另一个考虑是基于 auto 属性的两个限制:
virtual