![](/img/trans.png)
[英]LINQ to remove objects from a list of objects based on another list of objects
[英]Linq, from list of objects, create list of properties based on another property's value
我需要獲取bitPos> 2的risePeriods列表。
class Bit
{
public int bitPos { get; set; }
public int risePeriod { get; set; }
}
List<Bit> dataBits;
我試過了
IEnumerable<int> rpList = dataBits
.Where(bit => bit.bitPos > 2)
.Select(bit => bit.risePeriod);
和
IEnumerable<int> rpList = from bit in dataBits
where bit.bitPos > 2
select bit.risePeriod
以及其他方式,但是每種方法都返回整個dataBits列表,而不是僅僅一個risePeriods列表。 這應該很簡單-對嗎?
謝謝!
我已經嘗試過了,但似乎運行良好,因為我懷疑語法和邏輯看起來正確。 您可以嘗試添加對ToList
的調用,這將在檢查它是整數列表時更加清楚。 如果沒有,那么這里肯定還有其他事情。 這是我建議的代碼:
IEnumerable<int> rpList = dataBits
.Where(bit => bit.bitPos > 2)
.Select(bit => bit.risePeriod)
.ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.