這可能已經被處理了,所以我提前爲此道歉。LINQ GroupBy
無論如何,這是我的有點做作的例子,我希望它會在我的問題:
說我們有這些類
class WordExamples
{
public string word;
public List<Sentence> sentencesWithWord;
//constructor
public WordExamples(string word) {
this.word = word;
}
}
class Sentence
{
public List<string> words;
}
然後我們設置了兩個列表:
List<Sentence> sentences = GetSomeSentences();
List<WordExamples> wordExamples =
GetSomeWords().Select(w=>new WordExamples(w));
正如您所看到的WordExamples列表包含的單詞示例不完整,因爲它們沒有實例化sentencesWithWordList。
所以我需要的是一些整齊的Linq,它會設置它。即例如: foreach wordExample獲取包含該單詞的句子的子集並將其分配給sentencesWithWord。 (withouth的嵌套的循環,即是)
編輯: 添加公共訪問修飾符
當一個私有字段沒有用在聲明它的類中時,如何將任何代碼賦給'sentencesWithWord'? – svick 2012-01-30 14:33:15
@svick,是的,它是未經破解的僞代碼 – 2012-01-30 15:03:37