我需要你的幫助。Linq - OrderBy id當在另一個列表中的值
讓說:
public class myProduct
{
public string Tags {get;set;} // Comma seperated values
}
List<myProduct> myProducts = WhatEver // Feeding the list products
List<long> capacity = WhatEverAlso // Feed the list long values from somewhere
現在,我想做的事是爲了通過能力我的產品清單。
所以,如果一個myProduct.Tags
= 「89,3,6」 和能力= 「1,2,3,4,5,6」
第一會出現產品在他們1,則2等
問題是不排序他們,問題實際上是一些標籤不包含容量值。
編輯: 例如products.tags可能是「89,16,99」 所以它不包含任何的能力值。 EDIT2: 我不需要過濾產品,只需要訂購它們。
EDIT3: 我開始與var foo = myProducts.OrderBy(p => p.Tags.Split(',').Intersect(capacity).OrderBy(c => capacity).Any());
我覺得IM接近,但我不能想出休息。 :(
希望你明白我的問題,我的英語表達不是很好:\ 隨時問我任何額外信息
你怎麼知道哪些人做和沒有能力?你可以添加容量屬性到你的MyProduct類嗎?我感覺IEnumerable <>。Join()將成爲解決方案的一部分,但是如果沒有更多的信息,我就無法分辨出來。 – itsme86 2012-01-12 19:09:01
我很確定你需要一些foreach {}來做。 – 2012-01-12 19:09:53
@ itsme86 - 將問題添加到示例中 – Dementic 2012-01-12 19:11:30