gpt4 book ai didi

c# - 属性 Get v 方法的性能

转载 作者:可可西里 更新时间:2023-11-01 08:55:52 26 4
gpt4 key购买 nike

我有一个包含方法集合的类,我想知道使用方法而不是属性是否有任何性能提升?

一些方法相当复杂,但基本上返回一个 IEnumerable 对象集合,而其他方法则是简单的返回值。Where(x => x.property == "comparison") Linq查询。

示例

方法:

public IEnumerable<PenDataRow> ActivePens() => Pens.Where(x => x.Status == "Active");

属性:

public IEnumerable<PenDataRow> ActivePens => Pens.Where(x => x.Status == "Active");

将它们标记为属性或方法会更好吗?

最佳答案

属性在后台作为方法实现,因此绝对没有性能差异。 guidelines for choosing between a property and a method是语义的。

关于c# - 属性 Get v 方法的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12266652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com